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

Added primative rendering to window class

parent 22df8044
Branches
Tags
No related merge requests found
......@@ -10,6 +10,7 @@
#include <cstring>
#include <string>
#include "logger.h"
#include "maths/vec2.h"
const uint16_t SCREEN_HEIGHT = 600;
......@@ -53,6 +54,10 @@ class Window
SDL_Surface* _screenSurface;
SDL_Surface* _renderSurface;
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 _drawPoint( Vec2 point );
void initialise();
void clean();
};
\ No newline at end of file
......@@ -78,11 +78,46 @@ 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 );
// Render Example Primatives
this->_drawRect( SCREEN_WIDTH / 4, SCREEN_HEIGHT / 4, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 );
this->_drawRect( 0, 0, 10, 10 );
this->_drawLine( 0, SCREEN_HEIGHT / 2, SCREEN_WIDTH, SCREEN_HEIGHT / 2 );
for( uint16_t i = 0; i < SCREEN_HEIGHT; i += 10 )
{
this->_drawPoint( { SCREEN_WIDTH / 2, i } );
}
SDL_RenderPresent( this->_renderer );
}
SDL_Rect Window::_drawRect( int x, int y, uint16_t width, uint16_t height )
{
SDL_Rect fillRect = { x, y, width, height };
SDL_SetRenderDrawColor( this->_renderer, 0xFF, 0x00, 0x00, 0xFF );
SDL_RenderFillRect( this->_renderer, &fillRect );
SDL_Rect outlineRect = { x, y, width, height };
SDL_SetRenderDrawColor( this->_renderer, 0x00, 0xFF, 0x00, 0xFF );
SDL_RenderDrawRect( this->_renderer, &outlineRect );
return fillRect;
}
void Window::_drawLine( int16_t x1, int16_t y1, int16_t x2, int16_t y2 )
{
SDL_SetRenderDrawColor( this->_renderer, 0x00, 0x00, 0xFF, 0xFF );
SDL_RenderDrawLine( this->_renderer, x1, y1, x2, y2 );
}
void Window::_drawPoint( Vec2 point )
{
SDL_SetRenderDrawColor( this->_renderer, 0xFF, 0xFF, 0x00, 0xFF );
SDL_RenderDrawPoint( this->_renderer, point.x, point.y );
}
void Window::spawn()
{
this->_window = SDL_CreateWindow(
......@@ -133,6 +168,7 @@ void Window::processInput()
if( e.type == SDL_QUIT ) this->_toClose = true;
else if( e.type == SDL_KEYDOWN )
{
if( e.key.keysym.sym == SDLK_ESCAPE ) this->_toClose = true;
std::cout << "Key: " << e.key.keysym.sym << std::endl;
}
}
......
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