From 882d7ea12f9534a53f7a3b90e13e6fe3eefb2238 Mon Sep 17 00:00:00 2001 From: Jesper Stefansson Date: Sat, 8 Feb 2025 10:54:38 +0100 Subject: [PATCH] make sure to use the pixel format from the non-dummy window and clean things up a littl --- win32_wgl_window.cpp | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/win32_wgl_window.cpp b/win32_wgl_window.cpp index 40b97cb..6b63f91 100644 --- a/win32_wgl_window.cpp +++ b/win32_wgl_window.cpp @@ -42,19 +42,21 @@ AppWindow* create_window(WindowCreateDesc desc) HDC dummy_hdc = GetDC(dummy_hwnd); PANIC_IF(dummy_hdc == NULL, "unable to get dc from dummy window"); - PIXELFORMATDESCRIPTOR pfd{ - .nSize = sizeof pfd, - .nVersion = 1, - .dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, - .iPixelType = PFD_TYPE_RGBA, - .cColorBits = 32, - .cDepthBits = 24, - .cStencilBits = 8, - .iLayerType = PFD_MAIN_PLANE, - }; + { + PIXELFORMATDESCRIPTOR pfd{ + .nSize = sizeof pfd, + .nVersion = 1, + .dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, + .iPixelType = PFD_TYPE_RGBA, + .cColorBits = 32, + .cDepthBits = 24, + .cStencilBits = 8, + .iLayerType = PFD_MAIN_PLANE, + }; - int format = ChoosePixelFormat(dummy_hdc, &pfd); - if (!SetPixelFormat(dummy_hdc, format, &pfd)) PANIC("unable to set pixel format: (%d) %s", WIN32_ERR_STR); + int format = ChoosePixelFormat(dummy_hdc, &pfd); + if (!SetPixelFormat(dummy_hdc, format, &pfd)) PANIC("unable to set pixel format: (%d) %s", WIN32_ERR_STR); + } HGLRC dummy_glrc = wglCreateContext(dummy_hdc); PANIC_IF(dummy_glrc == NULL, "unable to create gl context: (%d) %s", WIN32_ERR_STR); @@ -65,6 +67,9 @@ AppWindow* create_window(WindowCreateDesc desc) LOAD_GL_ARB_PROC(wglChoosePixelFormat, gl_dll); LOAD_GL_ARB_PROC(wglCreateContextAttribs, gl_dll); + PANIC_IF(!wglChoosePixelFormat, "wglChoosePixelFormat proc not loaded, and no fallback available"); + PANIC_IF(!wglCreateContextAttribs, "wglCreateContextAttribs proc not loaded, and no fallback available"); + wnd->hwnd = CreateWindowExA( 0, wc.lpszClassName, @@ -80,8 +85,6 @@ AppWindow* create_window(WindowCreateDesc desc) wnd->hdc = GetDC(wnd->hwnd); PANIC_IF(wnd->hdc == NULL, "unable to get dc from window"); - PANIC_IF(!wglChoosePixelFormat, "wglChoosePixelFormat proc not loaded, and no fallback available"); - { i32 format_attribs[] = { WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, @@ -98,13 +101,12 @@ AppWindow* create_window(WindowCreateDesc desc) u32 formats_count; i32 format; wglChoosePixelFormat(wnd->hdc, format_attribs, NULL, 1, &format, &formats_count); - } - pfd = {}; - DescribePixelFormat(wnd->hdc, format, sizeof pfd, &pfd); - SetPixelFormat(wnd->hdc, format, &pfd); + PIXELFORMATDESCRIPTOR pfd = {}; + DescribePixelFormat(wnd->hdc, format, sizeof pfd, &pfd); + SetPixelFormat(wnd->hdc, format, &pfd); + } - PANIC_IF(!wglCreateContextAttribs, "wglCreateContextAttribs proc not loaded, and no fallback available"); { i32 context_attribs[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, 4,