Skip to content
Snippets Groups Projects
Commit 9ac891fe authored by Alfred Burgess's avatar Alfred Burgess
Browse files

Added viewport to SDL Window class

parent c4314958
No related merge requests found
......@@ -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();
......
......@@ -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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment