yupplemayham/YuppleMayham/include/graphics/glwindow.h

53 lines
No EOL
1 KiB
C++

#ifndef _H_GLWINDOW_H
#define _H_GLWINDOW_H
#include <SDL_video.h>
//#include <SDL_opengl.h>
#include <glad/glad.h>
class GLWindow
{
public:
GLWindow(const char* windowName, int width, int height) :
w(width),
h(height),
name(windowName) {};
~GLWindow();
bool Init();
void swap() { SDL_GL_SwapWindow(window); }
void makeCurrent() { SDL_GL_MakeCurrent(window, glContext); }
unsigned width() const { return w; }
unsigned height() const { return h; }
SDL_Window* getWindow() const { return window; }
const SDL_GLContext& getContext() const { return glContext; }
private:
SDL_Window* window = nullptr;
SDL_GLContext glContext = NULL;
unsigned w, h;
const char* name;
};
bool GLWindow::Init()
{
window = SDL_CreateWindow(name, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, SDL_WINDOW_OPENGL);
if (!window)
return false;
glContext = SDL_GL_CreateContext(window);
if (!glContext)
return false;
return true;
}
GLWindow::~GLWindow()
{
SDL_GL_DeleteContext(glContext);
SDL_DestroyWindow(window);
}
#endif // _H_GLWINDOW_H