summaryrefslogtreecommitdiff
path: root/src/gl_context.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gl_context.cpp')
-rw-r--r--src/gl_context.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/gl_context.cpp b/src/gl_context.cpp
new file mode 100644
index 0000000..2858e22
--- /dev/null
+++ b/src/gl_context.cpp
@@ -0,0 +1,32 @@
+#include "gl_context.hpp"
+#include <stdexcept>
+
+namespace bookmouse {
+
+GlContext::GlContext(SdlMainWindow& mainWindow)
+{
+ m_context = SDL_GL_CreateContext(mainWindow.window());
+ if (m_context == nullptr) {
+ auto error = SDL_GetError();
+ throw std::runtime_error{error};
+ }
+
+ auto status = SDL_GL_MakeCurrent(mainWindow.window(), m_context);
+ if (status != 0) {
+ auto error = SDL_GetError();
+ throw std::runtime_error{error};
+ }
+ status = SDL_GL_SetSwapInterval(1); // Enable vsync
+ if (status != 0) {
+ auto error = SDL_GetError();
+ throw std::runtime_error{error};
+ }
+}
+
+GlContext::~GlContext()
+{
+ SDL_GL_DeleteContext(m_context);
+}
+
+
+} // namespace bookmouse