call the render callback on window size and move.
This commit is contained in:
parent
8e1fc6e7ee
commit
159136a6eb
3 changed files with 29 additions and 7 deletions
|
|
@ -27,16 +27,20 @@
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
bool RunFrame(void)
|
bool RunFrame(void)
|
||||||
{
|
{
|
||||||
if (WindowShouldClose())
|
if (WindowShouldClose())
|
||||||
return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,6 +54,7 @@ int main(void)
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
|
|
|
||||||
|
|
@ -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 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 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 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
|
// Input callbacks events
|
||||||
static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods); // GLFW3 Keyboard Callback, runs on key pressed
|
static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods); // GLFW3 Keyboard Callback, runs on key pressed
|
||||||
|
|
@ -1439,16 +1440,22 @@ void WindowRefreshCallback(GLFWwindow* window)
|
||||||
return;
|
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();
|
CORE.Window.updateCallback();
|
||||||
|
|
||||||
rlDrawRenderBatchActive();
|
rlDrawRenderBatchActive();
|
||||||
|
|
||||||
SwapScreenBuffer();
|
SwapScreenBuffer();
|
||||||
CORE.Time.current = GetTime();
|
CORE.Time.current = GetTime();
|
||||||
CORE.Time.draw = CORE.Time.current - CORE.Time.previous;
|
CORE.Time.draw = CORE.Time.current - CORE.Time.previous;
|
||||||
CORE.Time.previous = CORE.Time.current;
|
CORE.Time.previous = CORE.Time.current;
|
||||||
|
|
||||||
SwapScreenBuffer(); // Copy back buffer to front buffer (screen)
|
|
||||||
|
|
||||||
// Frame time control system
|
// Frame time control system
|
||||||
CORE.Time.current = GetTime();
|
CORE.Time.current = GetTime();
|
||||||
CORE.Time.draw = CORE.Time.current - CORE.Time.previous;
|
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.frame = CORE.Time.update + CORE.Time.draw;
|
||||||
|
|
||||||
CORE.Time.frameCounter++;
|
CORE.Time.frameCounter++;
|
||||||
|
|
||||||
|
CORE.Window.wasDirtyThisFrame = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize platform: graphics, inputs and more
|
// Initialize platform: graphics, inputs and more
|
||||||
|
|
@ -2026,6 +2035,7 @@ static void WindowPosCallback(GLFWwindow *window, int x, int y)
|
||||||
// Set current window position
|
// Set current window position
|
||||||
CORE.Window.position.x = x;
|
CORE.Window.position.x = x;
|
||||||
CORE.Window.position.y = y;
|
CORE.Window.position.y = y;
|
||||||
|
WindowRefreshCallback(window); // Force window refresh on position change
|
||||||
}
|
}
|
||||||
|
|
||||||
// GLFW3: Window iconify callback, runs when window is minimized/restored
|
// GLFW3: Window iconify callback, runs when window is minimized/restored
|
||||||
|
|
|
||||||
13
src/rcore.c
13
src/rcore.c
|
|
@ -319,7 +319,7 @@ typedef struct CoreData {
|
||||||
unsigned int dropFileCount; // Count dropped files strings
|
unsigned int dropFileCount; // Count dropped files strings
|
||||||
|
|
||||||
bool(*updateCallback)(void); // Optional user defined callback to draw a frame
|
bool(*updateCallback)(void); // Optional user defined callback to draw a frame
|
||||||
|
bool wasDirtyThisFrame;
|
||||||
} Window;
|
} Window;
|
||||||
struct {
|
struct {
|
||||||
const char *basePath; // Base path for data storage
|
const char *basePath; // Base path for data storage
|
||||||
|
|
@ -743,12 +743,19 @@ static bool RunLoop = false;
|
||||||
|
|
||||||
void ProcessSingleFrame(void)
|
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();
|
BeginDrawing();
|
||||||
RunLoop = CORE.Window.updateCallback();
|
RunLoop = CORE.Window.updateCallback();
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
||||||
#if defined(SUPPORT_CUSTOM_FRAME_CONTROL)
|
#if SUPPORT_CUSTOM_FRAME_CONTROL
|
||||||
SwapBuffers();
|
SwapScreenBuffer();
|
||||||
PollInputEvents();
|
PollInputEvents();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue