spirit/src/window/window.cpp

65 lines
1.3 KiB
C++

#include "window.h"
Window::Window(int width, int height, int sdlOption)
{
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0)
{
cout << "Failed to initialize the SDL2 library\n";
this->quit();
}
this->window = SDL_CreateWindow("Spirit", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, sdlOption);
if(!(this->window))
{
cout << "Failed to create window: " << SDL_GetError() << "\n";
this->quit();
}
SDL_SetWindowResizable(this->window, SDL_TRUE);
this->spritesheet = SDL_LoadBMP("./spritesheet.bmp");
if(!spritesheet)
{
cout << "Failed to open spritesheet file\n";
this->quit();
}
this->surface = SDL_GetWindowSurface(this->window);
if(!surface)
{
cout << "Failed to get the surface from the window" << SDL_GetError() << "\n";
this->quit();
}
};
void Window::clear()
{
SDL_FillRect(this->surface, NULL, 0x000000);
}
void Window::draw()
{
SDL_FillRect(this->surface, NULL, 0x000000);
}
void Window::update()
{
SDL_UpdateWindowSurface(this->window);
this->surface = SDL_GetWindowSurface(this->window);
if(!surface)
{
cout << "Failed to get the surface from the window" << SDL_GetError() << "\n";
this->quit();
}
}
void Window::quit()
{
SDL_Quit();
exit(0);
}