displayManager.h 1.5 KB

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