From 159136a6ebcf6b73508d728bdd9eff8d9de659da Mon Sep 17 00:00:00 2001 From: Jeff Myers Date: Tue, 30 Jun 2026 21:11:26 -0700 Subject: [PATCH] call the render callback on window size and move. --- examples/core/core_basic_window.c | 9 +++++++-- src/platforms/rcore_desktop_glfw.c | 14 ++++++++++++-- src/rcore.c | 13 ++++++++++--- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/examples/core/core_basic_window.c b/examples/core/core_basic_window.c index b43662d2e..6e48acb8f 100644 --- a/examples/core/core_basic_window.c +++ b/examples/core/core_basic_window.c @@ -27,16 +27,20 @@ ********************************************************************************************/ #include "raylib.h" +#include bool RunFrame(void) { if (WindowShouldClose()) return false; - ClearBackground(RAYWHITE); + ClearBackground(BLACK); - DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY); + float offset = cosf(GetTime() * 2.0f) *60.0f; + DrawTextEx(GetFontDefault(), "Congrats! You created your first window!", (Vector2) { 190, 200 + offset}, 20, 2, LIGHTGRAY); + DrawFPS(10, 10); + DrawText(TextFormat("FrameTime %0.3f", GetFrameTime()), 10, 30, 20, GRAY); return true; } @@ -50,6 +54,7 @@ int main(void) const int screenWidth = 800; const int screenHeight = 450; + SetConfigFlags(FLAG_WINDOW_RESIZABLE); InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window"); SetTargetFPS(60); // Set our game to run at 60 frames-per-second diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index f776a10e4..3d2377eed 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -144,6 +144,7 @@ static void WindowIconifyCallback(GLFWwindow *window, int iconified); static void WindowMaximizeCallback(GLFWwindow *window, int maximized); // GLFW3 Window Maximize Callback, runs when window is maximized static void WindowFocusCallback(GLFWwindow *window, int focused); // GLFW3 WindowFocus Callback, runs when window get/lose focus static void WindowDropCallback(GLFWwindow *window, int count, const char **paths); // GLFW3 Window Drop Callback, runs when drop files into window +static void WindowRefreshCallback(GLFWwindow* window); // GLFW3 Window Refresh Callback, runs when window content needs to be refreshed // Input callbacks events static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods); // GLFW3 Keyboard Callback, runs on key pressed @@ -1438,17 +1439,23 @@ void WindowRefreshCallback(GLFWwindow* window) { return; } + + CORE.Time.current = GetTime(); // Number of elapsed seconds since InitTimer() + CORE.Time.update = CORE.Time.current - CORE.Time.previous; + CORE.Time.previous = CORE.Time.current; + + rlLoadIdentity(); // Reset current matrix (modelview) + rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale)); // Apply screen scaling CORE.Window.updateCallback(); rlDrawRenderBatchActive(); + SwapScreenBuffer(); CORE.Time.current = GetTime(); CORE.Time.draw = CORE.Time.current - CORE.Time.previous; CORE.Time.previous = CORE.Time.current; - SwapScreenBuffer(); // Copy back buffer to front buffer (screen) - // Frame time control system CORE.Time.current = GetTime(); CORE.Time.draw = CORE.Time.current - CORE.Time.previous; @@ -1457,6 +1464,8 @@ void WindowRefreshCallback(GLFWwindow* window) CORE.Time.frame = CORE.Time.update + CORE.Time.draw; CORE.Time.frameCounter++; + + CORE.Window.wasDirtyThisFrame = true; } // Initialize platform: graphics, inputs and more @@ -2026,6 +2035,7 @@ static void WindowPosCallback(GLFWwindow *window, int x, int y) // Set current window position CORE.Window.position.x = x; CORE.Window.position.y = y; + WindowRefreshCallback(window); // Force window refresh on position change } // GLFW3: Window iconify callback, runs when window is minimized/restored diff --git a/src/rcore.c b/src/rcore.c index be01019d9..209c4fa53 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -319,7 +319,7 @@ typedef struct CoreData { unsigned int dropFileCount; // Count dropped files strings bool(*updateCallback)(void); // Optional user defined callback to draw a frame - + bool wasDirtyThisFrame; } Window; struct { const char *basePath; // Base path for data storage @@ -743,12 +743,19 @@ static bool RunLoop = false; void ProcessSingleFrame(void) { + // if the dirty callback rendered this frame, don't double render, skip it until the next frame + if (CORE.Window.wasDirtyThisFrame) + { + CORE.Window.wasDirtyThisFrame = false; + return; + } + BeginDrawing(); RunLoop = CORE.Window.updateCallback(); EndDrawing(); -#if defined(SUPPORT_CUSTOM_FRAME_CONTROL) - SwapBuffers(); +#if SUPPORT_CUSTOM_FRAME_CONTROL + SwapScreenBuffer(); PollInputEvents(); #endif }