The header image.h where the variabel is declared:
Code:
#ifndef IMAGE_H
#define IMAGE_H
/****************************************************************
* SHARED VARIABLES
****************************************************************/
extern SDL_Surface *img; // <--------------------------------- Variable here
/****************************************************************
* EXPORTED FUNCTIONS
****************************************************************/
void UpdateImage();
#endif //IMAGE_H
One of the source files inluding image.h (image.cpp):
Code:
/****************************************************************
* INCLUDES
****************************************************************/
#include <cstdio>
#include <cstdlib>
#include "SDL/SDL.h"
#include <string>
#include <cmath>
using namespace std;
#include "wavetest.h"
#include "image.h"
/****************************************************************
* MACROS
****************************************************************/
#define PIXEL(s, x, y) ((Uint32 *)(s)->pixels)[(x) + (y)*(s)->w]
/****************************************************************
* VARIABLE DECLARATION
****************************************************************/
SDL_Surface *img; // <--------------------------------- Variable here
/****************************************************************
* NOT EXPORTED FUNCTIONS
****************************************************************/
/****************************************************************
* EXPORTED FUNCTIONS
****************************************************************/
void UpdateImage() {
int x, y;
for (y = 0; y < img->w; y++) {
for (x = 0; x < img->h; x++) {
PIXEL(img, x, y) = rand()&(1<<(24-1));
}
}
}
Another one of them (main.cpp):
Code:
/****************************************************************
* INCLUDES
****************************************************************/
#include <cstdio>
#include <cstdlib>
#include "SDL/SDL.h"
#include <string>
using namespace std;
#include "wavetest.h"
#include "main.h"
#include "SDL_functions.h"
#include "image.h"
/****************************************************************
* VARIABLE DECLARATION
****************************************************************/
const int IMG_WIDTH = 640;
const int IMG_HEIGHT = 480;
const int IMG_BPP = 32;
SDL_Surface *img = 0; // <--------------------------------- Variable here
/****************************************************************
* NOT EXPORTED FUNCTIONS
****************************************************************/
int main(int argc, char* args[]) {
InitSDL(img, IMG_WIDTH, IMG_HEIGHT, IMG_BPP, "Wavetest");
do {
} while(1);
QuitSDL();
}
/****************************************************************
* EXPORTED FUNCTIONS
****************************************************************/
I tried to use the extern keyword but it didn't matter.
And if there is something bad or uggly in the code, it's no big deal, I'm only doing this as a hobby anyway.