diff options
author | Dominick Allen <djallen@librehumanitas.org> | 2024-09-23 23:53:01 -0500 |
---|---|---|
committer | Dominick Allen <djallen@librehumanitas.org> | 2024-09-23 23:53:01 -0500 |
commit | b4a17e3a28f31217c79faa160f5e6abd720da054 (patch) | |
tree | 9e95862b192aa6c14b86a820ef77f290e46969c8 /src/sdl_main_window.cpp | |
parent | cae8b633fc8723bcc35944298335ad48844d2bf0 (diff) |
Applying RAII types
Diffstat (limited to 'src/sdl_main_window.cpp')
-rw-r--r-- | src/sdl_main_window.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/sdl_main_window.cpp b/src/sdl_main_window.cpp new file mode 100644 index 0000000..54b5388 --- /dev/null +++ b/src/sdl_main_window.cpp @@ -0,0 +1,34 @@ +#include "sdl_main_window.hpp" + +#include <stdexcept> + +namespace bookmouse { + +SdlMainWindow::SdlMainWindow(const SdlContext& sdlContext) +{ + sdlContext.setAttribute(SDL_GL_DOUBLEBUFFER, 1); + sdlContext.setAttribute(SDL_GL_DEPTH_SIZE, 24); + sdlContext.setAttribute(SDL_GL_STENCIL_SIZE, 8); + + SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | + SDL_WINDOW_ALLOW_HIGHDPI); + m_window = SDL_CreateWindow( + "Dear ImGui SDL2+OpenGL3 example", + SDL_WINDOWPOS_CENTERED, + SDL_WINDOWPOS_CENTERED, + 1280, + 720, + window_flags); + + if (m_window == nullptr) { + const auto* lastError = SDL_GetError(); + throw std::runtime_error{lastError}; + } +} + +SdlMainWindow::~SdlMainWindow() +{ + SDL_DestroyWindow(m_window); +} + +} // namespace bookmouse |