From b004531efbd20b2b814a14e266aa8ca18e81d477 Mon Sep 17 00:00:00 2001 From: SuperUserNameMan <9801802+SuperUserNameMan@users.noreply.github.com> Date: Thu, 11 Jul 2024 19:02:47 +0200 Subject: [PATCH] immediate access to `GetScreenWidth/Height()`, `GetRenderWidth/Height()` Call `WindowSizeCallback()` manually so we don't have to wait for after the next `EndDrawing()` to have access to up to date `GetScreenWidth()` etc value. --- src/platforms/rcore_desktop_glfw.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index 93d6033c5..18b8a809c 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -190,7 +190,14 @@ void ToggleFullscreen(void) CORE.Window.previousScreen.width = renderingWidth; CORE.Window.previousScreen.height = renderingHeight; + // GLFW will pick the best monitor resolution it can find for the size of rendering : + // TODO pick the resolution ourself and try to rescale and center with black borders glfwSetWindowMonitor(platform.handle, monitor, 0, 0, renderingWidth, renderingHeight, GLFW_DONT_CARE); + + // GLFW will call WindowSizeCallback too late after EndDrawing() + // Let's call it already so the user can access updated values without further delay : + const GLFWvidmode *mode = glfwGetVideoMode( monitor ); + WindowSizeCallback(platform.handle, mode->width, mode->height); } } @@ -199,7 +206,12 @@ void ToggleFullscreen(void) CORE.Window.fullscreen = false; CORE.Window.flags &= ~FLAG_FULLSCREEN_MODE; + // Ask GLFW to restore the window and the previous monitor resolution : glfwSetWindowMonitor(platform.handle, NULL, CORE.Window.previousPosition.x, CORE.Window.previousPosition.y, CORE.Window.previousScreen.width, CORE.Window.previousScreen.height, GLFW_DONT_CARE); + + // GLFW will call WindowSizeCallback too late after EndDrawing() + // Let's call it already so the user can access updated values without further delay : + WindowSizeCallback(platform.handle, CORE.Window.previousScreen.width, CORE.Window.previousScreen.height); } // Try to enable GPU V-Sync, so frames are limited to screen refresh rate (60Hz -> 60 FPS) @@ -246,9 +258,9 @@ void ToggleBorderlessWindowed(void) // Ask fullscreen window : glfwSetWindowMonitor(platform.handle, monitors[monitor], 0, 0, mode->width, mode->height, mode->refreshRate); - // Let's not wait for GLFW to call WindowSizeCallback to update these values : - CORE.Window.screen.width = mode->width; - CORE.Window.screen.height = mode->height; + // GLFW will call WindowSizeCallback too late after EndDrawing() + // Let's call it already so the user can access updated values without further delay : + WindowSizeCallback(platform.handle, mode->width, mode->height); // Refocus window glfwFocusWindow(platform.handle); @@ -265,9 +277,9 @@ void ToggleBorderlessWindowed(void) glfwSetWindowMonitor(platform.handle, NULL, prevPosX, prevPosY, prevWidth, prevHeight, GLFW_DONT_CARE); - // Let's not wait for GLFW to call WindowSizeCallback to update these values : - CORE.Window.screen.width = prevWidth; - CORE.Window.screen.height = prevHeight; + // GLFW will call WindowSizeCallback too late after EndDrawing() + // Let's call it already so the user can access updated values without further delay : + WindowSizeCallback(platform.handle, prevWidth, prevHeight); // Refocus window glfwFocusWindow(platform.handle);