Bonjour.
J'ai deux classes, CInit (qui contient la fonction InitSDL) et CBMP (qui contient la fonction ShowBMP), ces deux class font appels à screen qui est déini de la manière suivante (dans cinit.cpp) :
SDL_Surface *screen;
Mon problème : comment rendre screen utilisable par les deux fonctions ?
J'ai utilisé un fichier .h intermédiaire, mais j'ai eu un problème de multiple définition de screen (malgrès l'utilisation de #ifndef, etc.).
Merci.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 #ifndef CINIT_H #define CINIT_H class CInit { public: CInit(); virtual ~CInit(void); void InitSDL(int,int,int,int); }; #endif
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 #include "include.h" #include "cinit.h" CInit::CInit() { } CInit::~CInit() { } SDL_Surface *screen; // Fonction d'initialisation de SDL extern "C" __declspec(dllexport) void InitSDL(int x,int y,int bpp,int fullscreen) { Uint32 flagsinit=SDL_HWSURFACE|SDL_DOUBLEBUF; if (fullscreen) flagsinit|=SDL_FULLSCREEN; SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER); if(SDL_Init(SDL_INIT_VIDEO) == -1) { printf("Impossible d'initialiser SDL : %s\n", SDL_GetError()); exit(1); } atexit(SDL_Quit); screen=SDL_SetVideoMode(x,y,bpp,flagsinit); if(screen == NULL) { printf("Imposible de régler les paramètres vidéos : %s\n", SDL_GetError()); exit(1); } SDL_ShowCursor(0); }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 #ifndef CBMP_H #define CBMP_H class CBMP { public: CBMP(); virtual ~CBMP(void); void ShowBMP(const char*); }; #endifPS: j'utilise Dev-c++ 4.9.9.0
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 #include "include.h" #include "cbmp.h" CBMP::CBMP() { } CBMP::~CBMP() { } SDL_Surface *image; extern "C" __declspec(dllexport) void ShowBMP(const char* NomImage) { image = SDL_LoadBMP(NomImage); if(image == NULL) { printf("Impossible de charger l'image : %s\n", SDL_GetError()); exit(1); } SDL_BlitSurface(image, NULL, screen, NULL); SDL_FreeSurface(image); SDL_UpdateRect(screen, 0, 0, 0, 0); }
Partager