Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef _UTILS_RENDERER_HPP
- #define _UTILS_RENDERER_HPP
- #include <SDL2/SDL.h>
- #define RENDERER_WINDOWED (0)
- #define RENDERER_FULLSCREEN (1)
- #define RENDERER_BORDERLESS (2)
- class renderer_class {
- SDL_bool _valid = SDL_FALSE;
- //'was _window created by constructor?'
- SDL_bool _windowCreated = SDL_FALSE;
- SDL_Window* _window = nullptr;
- SDL_Renderer* _renderer = nullptr;
- SDL_Texture* _texture = nullptr;
- SDL_Texture* _target = nullptr; //user-defined render target
- SDL_Point _windowSize;
- SDL_Point _logicalSize = {-1,-1};
- Uint32 _windowID = 0;
- Uint32 _windowFlags;
- int _fullscreenMode = 0;
- void _freeWindowSafely(){
- if(_window!=nullptr && _windowCreated){
- SDL_DestroyWindow(_window);
- _window = nullptr;
- }
- }
- void _freeRendererSafely(){
- if(_renderer != nullptr){
- SDL_DestroyRenderer(_renderer);
- _renderer = nullptr;
- }
- }
- void _freeTextureSafely(){
- if(_texture != nullptr){
- SDL_DestroyTexture(_texture);
- _texture = nullptr;
- }
- }
- public:
- SDL_bool isValid(){ return _valid; }
- renderer_class(){}
- renderer_class(SDL_Point windowSize,
- Uint32 windowFlags = 0,
- SDL_Point textureSize = {-1,-1},
- SDL_Window* window = nullptr);
- ~renderer_class(){
- _freeTextureSafely();
- _freeRendererSafely();
- _freeWindowSafely();
- _valid = SDL_FALSE;
- }
- SDL_Window* getWindow(){ return _window; }
- SDL_Renderer* getRenderer(){ return _renderer; }
- SDL_Texture* getTexture(){ return _texture; }
- SDL_Texture* getTarget(){ return _target; }
- SDL_Point getWindowSize(){ return _windowSize; }
- SDL_Point getRendererSize(){ return _logicalSize; }
- SDL_Point getFullscreenSize();
- Uint32 getWindowID(){ return _windowID; }
- Uint32 getWindowFlags(){ return _windowFlags; }
- int getFullscreenMode(){ return _fullscreenMode; }
- void setFullscreen(int mode); //0,1,2 = windowed, fullscreen, windowed borderless
- void setSize(SDL_Point windowSize = {-1,-1}, SDL_Point logicalSize = {-1,-1});
- void setTarget(SDL_Texture* target = nullptr);
- void setDrawBlendMode(SDL_BlendMode blendMode = SDL_BLENDMODE_NONE);
- void setDrawColor(SDL_Color newColor = {0,0,0,255});
- void present();
- void clear();
- void copy(SDL_Texture* texture,
- const SDL_Rect* srcRect = nullptr,
- const SDL_Rect* dstRect = nullptr);
- };
- #endif /* _UTILS_RENDERER_HPP */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement