From a312a8ad42915352ccbc2a89eb261ff81dd99105 Mon Sep 17 00:00:00 2001 From: Keyz <171625499+keyzeuh@users.noreply.github.com> Date: Sat, 15 Nov 2025 01:04:23 +0100 Subject: [PATCH] Fix high DPI render size and window deformation --- src/platforms/rcore_desktop_glfw.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index bf383031b826..4e288203bd59 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -1808,30 +1808,35 @@ static void WindowSizeCallback(GLFWwindow *window, int width, int height) // WARNING: On window minimization, callback is called, // but we don't want to change internal screen values, it breaks things if ((width == 0) || (height == 0)) return; + int fbWidth, fbHeight; + glfwGetFramebufferSize(window, &fbWidth, &fbHeight); // Reset viewport and projection matrix for new size - SetupViewport(width, height); + SetupViewport(fbWidth, fbHeight); - CORE.Window.currentFbo.width = width; - CORE.Window.currentFbo.height = height; + CORE.Window.currentFbo.width = fbWidth; + CORE.Window.currentFbo.height = fbHeight; CORE.Window.resizedLastFrame = true; if (IsWindowFullscreen()) return; + int logicalWidth = width; + int logicalHeight = height; // if we are doing automatic DPI scaling, then the "screen" size is divided by the window scale if (IsWindowState(FLAG_WINDOW_HIGHDPI)) { - width = (int)(width/GetWindowScaleDPI().x); - height = (int)(height/GetWindowScaleDPI().y); + Vector2 dpiScale = GetWindowScaleDPI(); + logicalWidth = (int)(fbWidth / dpiScale.x); + logicalHeight = (int)(fbHeight / dpiScale.y); } // Set render size - CORE.Window.render.width = width; - CORE.Window.render.height = height; + CORE.Window.render.width = fbWidth; + CORE.Window.render.height = fbHeight; // Set current screen size - CORE.Window.screen.width = width; - CORE.Window.screen.height = height; + CORE.Window.screen.width = logicalWidth; + CORE.Window.screen.height = logicalHeight; // WARNING: If using a render texture, it is not scaled to new size }