displayManager.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef DISPLAYMANAGER_H
  2. #define DISPLAYMANAGER_H
  3. // ===============================
  4. // AUTHOR : Angel Ortiz (angelo12 AT vt DOT edu)
  5. // CREATE DATE : 2018-07-10
  6. // PURPOSE : Manages the SDL screen itself and drawing to the display.
  7. // ===============================
  8. // SPECIAL NOTES: Uses the old SDL1.2 backend because it's significantly faster
  9. // for pure software rendering. Using the new one would incur a 6ms penalty even on
  10. // empty frames. Probably has to do with sending data to the gpu every frame.
  11. // ===============================
  12. //Includes
  13. #include "SDL.h"
  14. #include "buffer.h"
  15. class DisplayManager{
  16. public:
  17. //The screen size is fixed and set at compile time along with other important
  18. //Display related values.
  19. const static int SCREEN_WIDTH = 1280; //640 1280
  20. const static int SCREEN_HEIGHT = 720; //480 720
  21. const static int SCREEN_PITCH = SCREEN_HEIGHT*sizeof(Uint32);
  22. constexpr static float SCREEN_ASPECT_RATIO = SCREEN_WIDTH /(float)SCREEN_HEIGHT;
  23. //Dummy Constructor / Destructor
  24. DisplayManager();
  25. ~DisplayManager();
  26. //Initializes SDL context and creates window according to above values
  27. bool startUp();
  28. void shutDown();
  29. //Swaps the pixel buffer with the window surface buffer and draws to screen
  30. void swapBuffers(Buffer<Uint32> *pixelBuffer);
  31. private:
  32. //Wrappers for SDL init functions
  33. bool startSDL();
  34. bool createWindow();
  35. bool createScreenSurface();
  36. //Pointers to the SDL window and surface
  37. SDL_Surface *mSurface;
  38. SDL_Window *mWindow;
  39. };
  40. #endif