main.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include <iostream>
  2. #include <SDL/SDL.h>
  3. #include "ElecField.h"
  4. int main ( int argc, char** argv )
  5. {
  6. /// [1] Démarrage
  7. // [1.1] Démarrages SDL
  8. if ( SDL_Init( SDL_INIT_VIDEO ) < 0)
  9. {
  10. std::cout << "Impossible d'initialiser la SDL: " << SDL_GetError() << std::endl;
  11. return 1;
  12. }
  13. // [1.2] Préparation de fermeture
  14. atexit(SDL_Quit);
  15. // [1.3] Para-fenêtre
  16. SDL_WM_SetCaption("Electric Field Pointer", 0);
  17. /// [2] Préparation des composants
  18. // [2.1] Préparation de la fenêtre
  19. SDL_Surface* screen = SDL_SetVideoMode(800, 800, 32,
  20. 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
  27. ElecField monChamp;
  28. monChamp.addCharge( 20, 0.20, 0.5, 200 );
  29. monChamp.addCharge( -1, 0.5, 0.5 );
  30. monChamp.renderGraph( 800, 800 );
  31. // [2.3] Préparation du texte
  32. /// [3] Boucle principale
  33. bool done = false;
  34. while (!done)
  35. {
  36. // [3.1] Gestion évènements
  37. SDL_Event event;
  38. while (SDL_PollEvent(&event))
  39. {
  40. switch (event.type)
  41. {
  42. case SDL_QUIT:
  43. done = true;
  44. break;
  45. case SDL_KEYDOWN:
  46. if (event.key.keysym.sym == SDLK_ESCAPE)
  47. done = true;
  48. break;
  49. } // end switch event type
  50. } // end of message processing
  51. // [3.2] Calculs
  52. // [3.3] Dessin des composants
  53. SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 128, 130));
  54. SDL_BlitSurface( monChamp.getGraph(), 0x0, screen, 0x0 );
  55. rectangleRGBA(screen, 5, 5, 795, 795, 255, 255, 0, 255);
  56. SDL_Flip(screen);
  57. } //fin bcl principale
  58. ///[4] Destruction des composants
  59. SDL_FreeSurface(screen);
  60. std::cout << "Aucune erreur détectée." << std::endl;
  61. return 0;
  62. }