/
SneakBug8
/
Project-Alice
Обзор
Документация
Войти
/
SneakBug8
/
Project-Alice
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/graphics/opengl_wrapper_win.cpp
92 строки
3 KB
ineveraskedforthis
complete province economy overview
07 авг 2025, 15:24
07 авг 2025, 15:24
fd408b8
Код
Авторство
О чём код?
#include "wglew.h" #include <cassert> #ifndef UNICODE #define UNICODE #endif #define NOMINMAX #define WIN32_LEAN_AND_MEAN #include "Windows.h" namespace ogl { void create_opengl_context(sys::state& state) { assert(state.win_ptr && state.win_ptr->hwnd && !state.open_gl.context); HDC window_dc = state.win_ptr->opengl_window_dc; PIXELFORMATDESCRIPTOR pfd; ZeroMemory(&pfd, sizeof(pfd)); pfd.nSize = sizeof(pfd); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 32; pfd.cDepthBits = 24; pfd.cStencilBits = 8; pfd.iLayerType = PFD_MAIN_PLANE; int const pixel_format = ChoosePixelFormat(window_dc, &pfd); SetPixelFormat(window_dc, pixel_format, &pfd); auto handle_to_ogl_dc = wglCreateContext(window_dc); wglMakeCurrent(window_dc, handle_to_ogl_dc); if(glewInit() != 0) { window::emit_error_message("GLEW failed to initialize", true); } if(!wglewIsSupported("WGL_ARB_create_context")) { window::emit_error_message("WGL_ARB_create_context not supported", true); } // Explicitly request for OpenGL 3.1 static const int attribs_3_1[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 3, WGL_CONTEXT_FLAGS_ARB, #ifndef NDEBUG WGL_CONTEXT_DEBUG_BIT_ARB | #endif 0, WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, 0, WGL_SAMPLE_BUFFERS_ARB, GL_TRUE, 0, WGL_SAMPLES_ARB, 8 }; state.open_gl.context = wglCreateContextAttribsARB(window_dc, nullptr, attribs_3_1); if(state.open_gl.context == nullptr) { window::emit_error_message("Unable to create WGL context", true); } wglMakeCurrent(window_dc, HGLRC(state.open_gl.context)); wglDeleteContext(handle_to_ogl_dc); // wglMakeCurrent(window_dc, HGLRC(state.open_gl.context)); #ifndef NDEBUG glDebugMessageCallback(debug_callback, nullptr); glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE); glDebugMessageControl(GL_DONT_CARE, GL_DEBUG_TYPE_OTHER, GL_DEBUG_SEVERITY_LOW, 0, nullptr, GL_FALSE); #endif if(wglewIsSupported("WGL_EXT_swap_control_tear") == 1) { wglSwapIntervalEXT(-1); } else if(wglewIsSupported("WGL_EXT_swap_control") == 1) { wglSwapIntervalEXT(1); } else { MessageBoxW(state.win_ptr->hwnd, L"WGL_EXT_swap_control_tear and WGL_EXT_swap_control not supported", L"OpenGL error", MB_OK); } } void shutdown_opengl(sys::state& state) { assert(state.win_ptr && state.win_ptr->hwnd && state.open_gl.context); wglMakeCurrent(state.win_ptr->opengl_window_dc, nullptr); wglDeleteContext(HGLRC(state.open_gl.context)); state.open_gl.context = nullptr; } } // namespace ogl