MCPcopy Create free account
hub / github.com/JeanPhilippeKernel/RendererEngine / OpenGLWindow

Method OpenGLWindow

ZEngine/src/SDL2Window/OpenGLWindow.cpp:16–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14namespace ZEngine::Window::SDLWin {
15
16 OpenGLWindow::OpenGLWindow(WindowProperty& prop)
17 : CoreWindow(), m_event(new SDL_Event{}, [](SDL_Event* e) { free(e); })
18
19 {
20 m_property = prop;
21 int sdl_init = 0;
22#ifdef _WIN32
23 sdl_init = SDL_Init(SDL_INIT_EVERYTHING);
24#else
25 sdl_init = SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_EVENTS);
26#endif
27 if (sdl_init != 0) {
28 ZENGINE_CORE_CRITICAL("Unable to initialize SDL subsystems : {}", SDL_GetError());
29 ZENGINE_EXIT_FAILURE();
30 }
31
32 const int loaded_gl_library = SDL_GL_LoadLibrary(NULL);
33 if (loaded_gl_library != 0) {
34 ZENGINE_CORE_CRITICAL("Failed to load OpenGL library...");
35 ZENGINE_EXIT_FAILURE();
36 }
37
38 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
39 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
40 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
41
42 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
43 SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
44
45#ifndef _WIN32
46 m_desired_gl_context_major_version = 3;
47 m_desired_gl_context_minor_version = 3;
48#endif
49 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, m_desired_gl_context_major_version);
50 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, m_desired_gl_context_minor_version);
51
52 m_native_window = SDL_CreateWindow(
53 m_property.Title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
54 m_property.Width, m_property.Height,
55 SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_CAPTURE
56 );
57 ZENGINE_CORE_INFO("Window created, Properties : Width = {0}, Height = {1}", m_property.Width, m_property.Height);
58
59 SDL_SetWindowData(m_native_window, CoreWindow::ATTACHED_PROPERTY, &m_property);
60 }
61
62 bool OpenGLWindow::HasContext() const {
63 return m_context != nullptr;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected