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

Changed system for image loading

parent ae8e15e0
Branches
No related merge requests found
......@@ -13,6 +13,17 @@
const uint16_t SCREEN_HEIGHT = 600;
const uint16_t SCREEN_WIDTH = 800;
//Key press surfaces constants
enum KeyPressSurfaces
{
KEY_PRESS_SURFACE_DEFAULT,
KEY_PRESS_SURFACE_UP,
KEY_PRESS_SURFACE_DOWN,
KEY_PRESS_SURFACE_LEFT,
KEY_PRESS_SURFACE_RIGHT,
KEY_PRESS_SURFACE_TOTAL
};
class Window
{
public:
......@@ -29,6 +40,7 @@ class Window
private:
bool _toClose;
bool _hasInit;
SDL_Surface* loadSurface( std::string path );
Logger& _logger;
SDL_Window* _window;
SDL_Surface* _screenSurface;
......
......@@ -39,9 +39,9 @@ int main( int argc, char* argv[] ) {
// Initialise Window
Window* window = new Window();
window->spawn();
window->loadMedia( "assets/hello-world.bmp" );
window->update();
window->spawn();
// Main Loop
while( state != Exit )
......
......@@ -29,18 +29,33 @@ void Window::initialise()
this->_hasInit = true;
}
void Window::loadMedia( std::string path )
SDL_Surface* Window::loadSurface( std::string path )
{
//Load splash image
this->_renderSurface = SDL_LoadBMP( path.c_str() );
if( this->_renderSurface == NULL )
SDL_Surface* optimizedSurface = NULL;
SDL_Surface* surface = SDL_LoadBMP( path.c_str() );
if( surface == NULL )
{
this->_logger.error( "Unable to load image" );
this->_logger.error( "Unable to load surface" );
return nullptr;
} else {
this->_logger.info( "Loaded image media" );
SDL_BlitSurface( this->_renderSurface, NULL, this->_screenSurface, NULL );
std::cout << "optimising...";
optimizedSurface = SDL_ConvertSurface(
surface, this->_screenSurface->format, 0
);
std::cout << "finished" << std::endl;
if( optimizedSurface == NULL )
{ this->_logger.error( "Unable to optimise image" ); }
}
SDL_FreeSurface( surface );
return optimizedSurface;
}
void Window::loadMedia( std::string path )
{
//Load splash image
this->_renderSurface = this->loadSurface( path.c_str() );
}
void Window::update() {
......@@ -73,6 +88,10 @@ void Window::processInput()
{
// std::cout << "event" << std::endl;
if( e.type == SDL_QUIT ) this->_toClose = true;
else if( e.type == SDL_KEYDOWN )
{
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