main.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include <iostream>
  2. #include <SDL.h>
  3. int main ( int argc, char** argv )
  4. {
  5. /// [1] Démarrage
  6. // [1.1] Démarrages SDL
  7. if ( SDL_Init( SDL_INIT_VIDEO ) < 0)
  8. {
  9. std::cout << "Impossible d'initialiser la SDL: " << SDL_GetError() << std::endl;
  10. return 1;
  11. }
  12. // [1.2] Préparation de fermeture
  13. atexit(SDL_Quit);
  14. // [1.3] Para-fenêtre
  15. SDL_WM_SetCaption("Application SDL", 0);
  16. /// [2] Préparation des composants
  17. // [2.1] Préparation de la fenêtre
  18. SDL_Surface* screen = SDL_SetVideoMode(640, 480, 16,
  19. SDL_HWSURFACE|SDL_DOUBLEBUF);
  20. if ( !screen )
  21. {
  22. std::cout << "Unable to set 640x480 video: " << SDL_GetError() << std::endl;
  23. return 1;
  24. }
  25. // [2.2] Préparation
  26. // [2.3] Préparation des ...
  27. /// [3] Boucle principale
  28. bool done = false;
  29. while (!done)
  30. {
  31. // [3.1] Gestion évènements
  32. SDL_Event event;
  33. while (SDL_PollEvent(&event))
  34. {
  35. switch (event.type)
  36. {
  37. case SDL_QUIT:
  38. done = true;
  39. break;
  40. case SDL_KEYDOWN:
  41. if (event.key.keysym.sym == SDLK_ESCAPE)
  42. done = true;
  43. break;
  44. } // end switch event type
  45. } // end of message processing
  46. // [3.2] Calculs
  47. // [3.3] Dessin des composants
  48. SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 255, 255));
  49. //
  50. SDL_Flip(screen);
  51. } //fin bcl principale
  52. ///[4] Destruction des composants
  53. SDL_FreeSurface(screen);
  54. std::cout << "Aucune erreur détectée." << std::endl;
  55. return 0;
  56. }