main.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include <iostream>
  2. #include "MetaDeg.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. int sc_w(640) ;
  19. int sc_h(480) ;
  20. SDL_Surface* screen = SDL_SetVideoMode(sc_w, sc_h, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
  21. if ( !screen )
  22. {
  23. std::cout << "Unable to set 640x480 video: " << SDL_GetError() << std::endl;
  24. return 1;
  25. }
  26. // [2.2] Préparation de l'espace
  27. MetaDeg mySpace;
  28. if ( !mySpace.init(sc_w, sc_h) )
  29. {
  30. std::cout << "Problème initialisation du Metaspace." << std::endl ;
  31. return 1;
  32. }
  33. SDL_Surface* meta_img(mySpace.getSurf());
  34. // [2.3] Préparation des calculs
  35. Uint32 mx(sc_w / 2) ;
  36. Uint32 my(sc_w / 2) ;
  37. /// [3] Boucle principale
  38. SDL_EnableKeyRepeat(10,10);
  39. bool done = false;
  40. while (!done)
  41. {
  42. // [3.1] Gestion évènements
  43. SDL_Event event;
  44. while (SDL_PollEvent(&event))
  45. {
  46. switch (event.type)
  47. {
  48. case SDL_QUIT:
  49. done = true;
  50. break;
  51. case SDL_MOUSEMOTION:
  52. mx = event.motion.x ;
  53. my = event.motion.y ;
  54. break;
  55. case SDL_KEYDOWN:
  56. switch (event.key.keysym.sym)
  57. {
  58. case SDLK_ESCAPE:
  59. done = true;
  60. break;
  61. case SDLK_UP:
  62. /*if (seuil < 30000)
  63. seuil += 1 ;
  64. mySpace.setSeuil(seuil);*/
  65. break;
  66. case SDLK_DOWN:
  67. /*if (seuil > 10)
  68. seuil -= 1 ;
  69. mySpace.setSeuil(seuil);*/
  70. break;
  71. default:
  72. break;
  73. }
  74. break;
  75. } // end switch event type
  76. } // end of message processing
  77. // [3.2] Calculs
  78. mySpace.clean();
  79. mySpace.deform(my, mx);
  80. mySpace.deform(180, 250);
  81. mySpace.draw();
  82. // [3.3] Dessin des composants
  83. SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 255, 255));
  84. SDL_BlitSurface(meta_img, 0, screen, 0);
  85. SDL_Flip(screen);
  86. } //fin bcl principale
  87. ///[4] Destruction des composants
  88. SDL_FreeSurface(screen);
  89. std::cout << "Aucune erreur détectée." << std::endl;
  90. return 0;
  91. }