opengl-playground/src/sdlmainwindow.cpp

37 lines
768 B
C++

#include <opengl-playground/sdlmainwindow.hpp>
SdlMainWindow::SdlMainWindow(int height, int width) : MainWindow()
{
this->width = width;
this->height = height;
this->window = NULL;
this->context = NULL;
}
SdlMainWindow::~SdlMainWindow()
{
if (this->window)
SDL_DestroyWindow(window);
}
void SdlMainWindow::show()
{
this->window = SDL_CreateWindow("OpenGL Playground", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
this->width, this->height, SDL_WINDOW_OPENGL);
return;
}
void SdlMainWindow::swapBuffer()
{
if (this->window)
SDL_GL_SwapWindow(this->window);
}
void SdlMainWindow::activateGlContext()
{
if (this->context == NULL)
this->context = SDL_GL_CreateContext(this->window);
else
SDL_GL_MakeCurrent(this->window, this->context);
}