diff --git a/include/window.h b/include/window.h index 258c1ab7030c893a7317ac12d2ed01adc7fd10af..3a2bdecb5414d06ca0003bdf547bc3d8f2ff516d 100644 --- a/include/window.h +++ b/include/window.h @@ -56,7 +56,11 @@ class Window SDL_Rect _drawRect( int x, int y, uint16_t width, uint16_t height ); void _drawLine( int16_t x1, int16_t y1, int16_t x2, int16_t y2 ); + // void _drawLine( Vec2 from, Vec2 to ); void _drawPoint( Vec2 point ); + // void _drawPoint( int16_t x, int16_t y ); + + SDL_Rect _createViewport( int16_t x, int16_t y, int16_t w, int16_t h ); void initialise(); void clean(); diff --git a/src/window.cpp b/src/window.cpp index efe1705b57845358bdd93fa4933d410fcff8f1df..fb74e8da224e50c7d2018f607725329ba90ef668 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -80,8 +80,8 @@ void Window::loadMedia( std::string path ) void Window::update() { SDL_SetRenderDrawColor( this->_renderer, 0xFF, 0xFF, 0xFF, 0xFF ); SDL_RenderClear( this->_renderer ); - SDL_RenderCopy( this->_renderer, this->_activeTexture, NULL, NULL ); + SDL_Rect core = this->_createViewport( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT ); // Render Example Primatives this->_drawRect( SCREEN_WIDTH / 4, SCREEN_HEIGHT / 4, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 ); this->_drawRect( 0, 0, 10, 10 ); @@ -91,6 +91,9 @@ void Window::update() { this->_drawPoint( { SCREEN_WIDTH / 2, i } ); } + SDL_Rect overlay = this->_createViewport( SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 ); + SDL_RenderCopy( this->_renderer, this->_activeTexture, NULL, NULL ); + SDL_RenderPresent( this->_renderer ); } @@ -197,4 +200,15 @@ void Window::clean() SDL_Quit(); this->_logger.info( "Window Closed and clean" ); +} + +SDL_Rect Window::_createViewport( int16_t x, int16_t y, int16_t w, int16_t h ) +{ + SDL_Rect viewport; + viewport.x = x; + viewport.y = y; + viewport.w = w; + viewport.h = h; + SDL_RenderSetViewport( this->_renderer, &viewport ); + return viewport; } \ No newline at end of file