Advertisement
Benjamin_Loison

Tutorial C++ SDL2.0 OpenGL (CodeBlocks)

Apr 13th, 2017
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. 1:telecharger CodeBlocks avec Mingw http://www.codeblocks.org/downloads/26 (codeblocks-16.01mingw-setup.exe).
  2. 2:installer
  3. 3:telecharger la bblioteque SDL https://www.libsdl.org/download-2.0.php (SDL2-devel-2.0.5-mingw.tar.gz dans development librairies)
  4. 4:decompresser et placer dans C:/Librairies
  5. 5:ouvrir CodeBlocks
  6. 6:creer un nouveau projet(empty project)
  7. 7:faire un clic droit sur le projet a gauche et aller dans properties
  8. 8:aller dans build target et cocher GUI application(dans debug et release) puis appuyer sur ok
  9. 9:aller dans settings>compiler
  10. 10:dans linker settings ajouter -lmingw32, -lSDL2main, -lSDL2, -lopengl32, -lglu32
  11. 11:dans search directories>compiler appuyez sur add et ajouter le dosier SDL2 dans le dossier include de i686-w64-mingw32 du dossier SDL normalement placé dans C:/Librairies (vous devriez avoir quelque chose comme C:\Librairies\SDL2-2.0.5\i686-w64-mingw32\include\SDL2)
  12. 12:dans search directories>linker ajoutez pareillement le dossier lib de la SDL(toujours la version i686-w64-mingw32)
  13. 13:cliquez sur ok
  14. 14:creez un nouveau fichier dans le projet
  15. 15:collez ce code dedans:
  16. #include <SDL.h>
  17. #include <GL/gl.h>
  18. #include <GL/glu.h>
  19.  
  20. int main(int argc, char *argv[])
  21. {
  22. SDL_Init(SDL_INIT_VIDEO);
  23. SDL_Window *screen = SDL_CreateWindow("Ma fenetre de jeu", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_OPENGL);
  24. SDL_GLContext glcontext = SDL_GL_CreateContext(screen);
  25. SDL_Event event;
  26.  
  27. while (continuer)
  28. {
  29. SDL_WaitEvent(&event);
  30. switch(event.type)
  31. {
  32. case SDL_QUIT:
  33. continuer = false;
  34. }
  35.  
  36. glClear(GL_COLOR_BUFFER_BIT);
  37.  
  38. glBegin(GL_TRIANGLES);
  39. glColor3ub(255,0,0); glVertex2d(-0.75,-0.75);
  40. glColor3ub(0,255,0); glVertex2d(0,0.75);
  41. glColor3ub(0,0,255); glVertex2d(0.75,-0.75);
  42. glEnd();
  43.  
  44. glFlush();
  45. SDL_GL_SwapWindow(screen);
  46. }
  47.  
  48. SDL_Quit();
  49. return 0;
  50. }
  51. 16:aller chercher SDL2.dll dans C:/Librairies/SDL2-2.0.5/i686-w64-mingw32/bin et le placer dans votre projet a côté du fichier .cpp
  52. 17:compilez et executez. Vous devriez voir apparaitre un triangle multicolore
  53. 18:si il y a une erreur reprenez toutes les etapes depuis le telechargement de la SDL.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement