Skip to content

Commit

Permalink
immediate access to GetScreenWidth/Height(), GetRenderWidth/Height()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
SuperUserNameMan authored Jul 11, 2024
1 parent 545665d commit b004531
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/platforms/rcore_desktop_glfw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit b004531

Please sign in to comment.