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/sdl_main_window.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/sdl_main_window.cpp (limited to 'src/sdl_main_window.cpp') 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 + +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 -- cgit v1.2.3