Bonjour,
je suis en train d'écrire un jeu avec opengl 4.0, et j'ai décidé que j'utiliserais sdl pour la création de fenêtre, gestion des touches et de la souris, etc...
Le problème c'est qu'après avoir débuggué une première version de test, je me rends compte qu'aucune des fonction sdl n'est reconnues (en fait, non pas tout à fait, je crois que je n'ai eu aucun message d'erreurs pour SDL_GL_SetAttribute, par exemple).
J'ai donc essayé de remonter à la source du problème, et j'ai isolée et simplifiée la partie du code fisant intervenir des fonctions sdl, et j'ai même essayé, en désespoir de cause, de réinstaller plusieurs fois la bibliothèque (j'utilise apt-get pour l'installer, et j'ai les bibliothèques suivantes: libsdl1.2-dev, libsdl1.2debian, libsdl-image1.2, libsdl1.2-dbg), rien n'y fait.
Voilà le code ultra simplifié pour tester le compilage de la sdl:
main.cpp:
Voilà le code d'arreur que me retourne le compilo (g++):
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 #include <SDL/SDL.h> #include <string> class Window { public: Window(std::string windowTitle, int width, int height); ~Window(); private: SDL_Window * m_mainwindow; SDL_GLContext m_maincontext; int m_width; int m_height; }; Window::Window(std::string windowTitle, int width, int height) { m_width = width; m_height = height; //~ if (SDL_Init(SDL_INIT_VIDEO) < 0) //~ exitOnError("fail to initialize the SDL window: %s", SDL_GetError()); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); m_mainwindow = SDL_CreateWindow(windowTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, m_width, m_height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); //~ if (!m_mainwindow) //~ exitOnError("Unable to create window: %s", SDL_GetError()); m_maincontext = SDL_GL_CreateContext(m_maincontext); SDL_GL_SetSwapInterval(1); } Window::~Window() { SDL_GL_DeleteContext(m_maincontext); SDL_DestroyWindow(m_mainwindow); SDL_Quit(); } int main() { Window window("Space Game", 512, 512); //~ Scene test(); //~ test.mainLoop(); return 0; }
main.cpp:11:3: erreur: ‘SDL_Window’ does not name a type
main.cpp:12:3: erreur: ‘SDL_GLContext’ does not name a type
main.cpp: In constructor ‘Window::Window(std::string, int, int)’:
main.cpp:26:25: erreur: ‘SDL_GL_CONTEXT_MAJOR_VERSION’ was not declared in this scope
main.cpp:27:25: erreur: ‘SDL_GL_CONTEXT_MINOR_VERSION’ was not declared in this scope
main.cpp:32:5: erreur: ‘m_mainwindow’ was not declared in this scope
main.cpp:32:50: erreur: ‘SDL_WINDOWPOS_CENTERED’ was not declared in this scope
main.cpp:33:28: erreur: ‘SDL_WINDOW_OPENGL’ was not declared in this scope
main.cpp:33:48: erreur: ‘SDL_WINDOW_SHOWN’ was not declared in this scope
main.cpp:33:67: erreur: ‘SDL_WINDOW_RESIZABLE’ was not declared in this scope
main.cpp:33:87: erreur: ‘SDL_CreateWindow’ was not declared in this scope
main.cpp:36:4: erreur: ‘m_maincontext’ was not declared in this scope
main.cpp:36:54: erreur: ‘SDL_GL_CreateContext’ was not declared in this scope
main.cpp:38:29: erreur: ‘SDL_GL_SetSwapInterval’ was not declared in this scope
main.cpp: In destructor ‘Window::~Window()’:
main.cpp:42:26: erreur: ‘m_maincontext’ was not declared in this scope
main.cpp:42:39: erreur: ‘SDL_GL_DeleteContext’ was not declared in this scope
main.cpp:43:23: erreur: ‘m_mainwindow’ was not declared in this scope
main.cpp:43:35: erreur: ‘SDL_DestroyWindow’ was not declared in this scope
Et enfin, voilà les comment je compile mon fichier main.cpp:
g++ main.cpp -o test $(sdl-config --cflags --libs)
J'ajouterais que j'ai même essayé de copier tel quel le code mit en exemple sur le site même de SDL (et qu'on peut voir en bas de page sur ce lien: http://wiki.libsdl.org/moin.cgi/SDL_...SDL\_Window%29) mais que j'ai toujours a peu près les même erreurs.
J'ai aussi essayé de ne pas utiliser sdl-config et de rentrer les options d'edition de liens moi-même lors de la compilation (avec -lSDL, -lSDL-main, etc...) mais que rien n'y fait.
Pour finir je dirais que j'ai fouillé le fichier SDL.h et tout les autres qui sont donné en lien, et que je n'y ait trouvé aucune mention à la fonction SDL_CreateWindow, par exemple.
Est-ce parce que cette fonction fait appelle à une bibliothèque supplémentaire, et que c'est de là que viendrais mon erreur?
Ou encore autre chose?
J'avaoue que cette histoire commence à me gonfler sérieusement.
Merci d'avance de votre réponse.
Partager