displayManager.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifndef DISPLAYMANAGER_H
  2. #define DISPLAYMANAGER_H
  3. #include "SDL.h"
  4. #include "buffer.h"
  5. //Manages all low level display and window SDL stuff
  6. //Currently set up to work using SDL2 hardware rendering
  7. //I tested software rendering and although it was faster for simple color passes
  8. //It was slower when I tried to implement alpha blending, so I decided to revert
  9. //Back to the hardware accelerated backend.
  10. class DisplayManager{
  11. public:
  12. const static int SCREEN_WIDTH = 640; //640 1280
  13. const static int SCREEN_HEIGHT = 480; //480 720
  14. const static int SCREEN_PITCH = SCREEN_HEIGHT*sizeof(Uint32);
  15. constexpr static float SCREEN_ASPECT_RATIO = SCREEN_WIDTH /(float)SCREEN_HEIGHT;
  16. //Dummy Constructor / Destructor
  17. DisplayManager();
  18. ~DisplayManager();
  19. //Initializes SDL context and creates window according to values above
  20. bool startUp();
  21. void shutDown();
  22. //Clear screens to draw color (Normally black)
  23. void clear();
  24. //Swaps the pixel buffer with the texture buffer and draws to screen
  25. void swapBuffers(Buffer<Uint32> *pixelBuffer);
  26. private:
  27. //Wrappers for SDL init functions
  28. bool startSDL();
  29. bool createWindow();
  30. bool createSDLRenderer();
  31. bool createScreenTexture();
  32. SDL_Texture *mTexture;
  33. SDL_Renderer *mSDLRenderer;
  34. SDL_Window *mWindow;
  35. //These are only really needed for the texture copying operation
  36. int mTexturePitch;
  37. void *mTexturePixels;
  38. };
  39. #endif