From 24c2b3cf01885a5d60ff49a8bcd89f889f093456 Mon Sep 17 00:00:00 2001 From: Jens Weggemann Date: Wed, 21 Jan 2026 19:52:47 +0100 Subject: [PATCH] Win32: Clear to black in WM_PAINT for transparent framebuffer windows The DWM redirection surface may contain undefined alpha values, causing the window to composite incorrectly. PatBlt with BLACKNESS clears both RGB and alpha to zero. --- src/win32_window.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/win32_window.c b/src/win32_window.c index 6427a673..2af2f05b 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1139,6 +1139,22 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l case WM_PAINT: { _glfwInputWindowDamage(window); + + // The DWM redirection surface starts with undefined alpha. + // Clear to BLACKNESS which should zero out the alpha components as well. + if (window->win32.transparent) + { + PAINTSTRUCT ps; + HDC hdc = BeginPaint(hWnd, &ps); + PatBlt(hdc, + ps.rcPaint.left, + ps.rcPaint.top, + ps.rcPaint.right - ps.rcPaint.left, + ps.rcPaint.bottom - ps.rcPaint.top, + BLACKNESS); + EndPaint(hWnd, &ps); + return 0; + } break; }