summaryrefslogtreecommitdiff
path: root/src/gl_context.cpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-09-23 23:53:01 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-09-23 23:53:01 -0500
commitb4a17e3a28f31217c79faa160f5e6abd720da054 (patch)
tree9e95862b192aa6c14b86a820ef77f290e46969c8 /src/gl_context.cpp
parentcae8b633fc8723bcc35944298335ad48844d2bf0 (diff)
Applying RAII types
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