Replies: 2 comments 3 replies
|
The artifact is a timing problem between the OS window manager and the OpenGL swap chain, not a raylib bug. When One caveat worth knowing: on Wayland, The workaround is to hook GLFW's window size callback and push a complete new frame before the compositor reads the buffer: #include "raylib.h"
#include "rlgl.h"
#include <GLFW/glfw3.h>
GLFWwindowsizefun originalWindowSizeCallback = NULL;
void DrawUI();
void CustomWindowSizeCallback(GLFWwindow* window, int width, int height) {
// Let raylib update its internal CORE.Window.screen state first
if (originalWindowSizeCallback) originalWindowSizeCallback(window, width, height);
// Render before the OS compositor reads the buffer
BeginDrawing();
DrawUI();
// Don't call EndDrawing(), it calls glfwPollEvents() internally,
// which is undefined behavior inside a GLFW callback and tends to crash.
// Flush and swap manually instead:
rlDrawRenderBatchActive();
glfwSwapBuffers(window);
}
void DrawUI() {
ClearBackground(RAYWHITE);
DrawText("No more artifacts!", 10, 10, 20, DARKGRAY);
// ... the rest of your UI
}
int main(void) {
InitWindow(800, 600, "Smooth Resize Solution");
GLFWwindow* glfwWindow = (GLFWwindow*)GetWindowHandle();
// Chain callbacks so raylib's internal handler still runs
originalWindowSizeCallback = glfwSetWindowSizeCallback(glfwWindow, CustomWindowSizeCallback);
while (!WindowShouldClose()) {
if (IsKeyPressed(KEY_SPACE)) {
SetWindowSize(1024, 768);
}
BeginDrawing();
DrawUI();
EndDrawing();
}
CloseWindow();
return 0;
}On HiDPI or Retina displays, also hook |
|
@mallory-scotton did you test it? does it work? I'll be surprised because provided code is incorrect... |
Uh oh!
There was an error while loading. Please reload this page.
Is there any way of calling SetWindowSize on an active window without creating frame artefacts?
I have a windowed application which allows opening/closing certain parts of the UI interactively, resulting in a changed window size (and sometimes position). Unfortunately, after SetWindowSize, the window content is visibly garbled for at least the remaining frame (depending on platform, it either moves or scales the current content instantly). That looks rather unprofessional.
There does not seem to be a means of synchronising resizing with framebuffer swaps. I tried various workarounds, including combinations of:
None of it helped much, the artefact frames remain, at least some of the times.
Has anybody else run into this problem and found a workable solution (on GLFW or other backend)?
All reactions