From b02cb5ed6c8d411d015f3c532f841875f046bcc4 Mon Sep 17 00:00:00 2001 From: Francisco Facioni Date: Sat, 24 Oct 2026 12:40:35 +0200 Subject: [PATCH] Take an adopted WGL context's pixel format from the DC it is current on Signed-off-by: Francisco Facioni --- src/wgl/device.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/wgl/device.rs b/src/wgl/device.rs index 117770c6..05456b44 100644 --- a/src/wgl/device.rs +++ b/src/wgl/device.rs @@ -47,7 +47,7 @@ use winapi::um::handleapi::INVALID_HANDLE_VALUE; use winapi::um::libloaderapi; use winapi::um::wingdi::{self, PIXELFORMATDESCRIPTOR}; use winapi::um::wingdi::{ - wglDeleteContext, wglGetCurrentContext, wglGetProcAddress, wglMakeCurrent, + wglDeleteContext, wglGetCurrentContext, wglGetCurrentDC, wglGetProcAddress, wglMakeCurrent, }; use winapi::um::winuser::{self, COLOR_BACKGROUND, CS_OWNDC, MSG, WM_CLOSE}; use winapi::um::winuser::{WNDCLASSA, WS_OVERLAPPEDWINDOW}; @@ -405,6 +405,10 @@ impl WglDevice { let gl = { let hidden_window_dc = hidden_window.get_dc(); let dc = hidden_window_dc.dc; + // `wglMakeCurrent` needs the DC to have the context's pixel format. + if wglGetCurrentContext() == native_context.0 { + set_dc_pixel_format(dc, wingdi::GetPixelFormat(wglGetCurrentDC())); + } let _guard = CurrentContextGuard::new(); let ok = wglMakeCurrent(dc, native_context.0); assert_ne!(ok, FALSE);