9#define WIN32_LEAN_AND_MEAN
16 assert(state.win_ptr && state.win_ptr->hwnd && !state.open_gl.context);
18 HDC window_dc = state.win_ptr->opengl_window_dc;
20 PIXELFORMATDESCRIPTOR pfd;
21 ZeroMemory(&pfd,
sizeof(pfd));
22 pfd.nSize =
sizeof(pfd);
24 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
25 pfd.iPixelType = PFD_TYPE_RGBA;
29 pfd.iLayerType = PFD_MAIN_PLANE;
30 int const pixel_format = ChoosePixelFormat(window_dc, &pfd);
31 SetPixelFormat(window_dc, pixel_format, &pfd);
33 auto handle_to_ogl_dc = wglCreateContext(window_dc);
34 wglMakeCurrent(window_dc, handle_to_ogl_dc);
40 if(!wglewIsSupported(
"WGL_ARB_create_context")) {
45 static const int attribs_3_1[] = {
46 WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
47 WGL_CONTEXT_MINOR_VERSION_ARB, 1,
48 WGL_CONTEXT_FLAGS_ARB,
50 WGL_CONTEXT_DEBUG_BIT_ARB |
53 WGL_CONTEXT_PROFILE_MASK_ARB,
54 WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
57 state.open_gl.context = wglCreateContextAttribsARB(window_dc,
nullptr, attribs_3_1);
58 if(state.open_gl.context ==
nullptr) {
62 wglMakeCurrent(window_dc, HGLRC(state.open_gl.context));
63 wglDeleteContext(handle_to_ogl_dc);
68 glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0,
nullptr, GL_TRUE);
69 glDebugMessageControl(GL_DONT_CARE, GL_DEBUG_TYPE_OTHER, GL_DEBUG_SEVERITY_LOW, 0,
nullptr, GL_FALSE);
72 if(wglewIsSupported(
"WGL_EXT_swap_control_tear") == 1) {
73 wglSwapIntervalEXT(-1);
74 }
else if(wglewIsSupported(
"WGL_EXT_swap_control") == 1) {
75 wglSwapIntervalEXT(1);
77 MessageBoxW(state.win_ptr->hwnd, L
"WGL_EXT_swap_control_tear and WGL_EXT_swap_control not supported", L
"OpenGL error", MB_OK);
82 assert(state.win_ptr && state.win_ptr->hwnd && state.open_gl.context);
83 wglMakeCurrent(state.win_ptr->opengl_window_dc,
nullptr);
84 wglDeleteContext(HGLRC(state.open_gl.context));
85 state.open_gl.context =
nullptr;
#define assert(condition)
void create_opengl_context(sys::state &state)
void shutdown_opengl(sys::state &state)
void debug_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei, GLchar const *message, void const *)
void emit_error_message(std::string const &content, bool fatal)