From b4a17e3a28f31217c79faa160f5e6abd720da054 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Mon, 23 Sep 2024 23:53:01 -0500 Subject: Applying RAII types --- src/gl_context.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/gl_context.cpp (limited to 'src/gl_context.cpp') 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 + +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 -- cgit v1.2.3