raysan5 / raylib

A simple and easy-to-use library to enjoy videogames programming
http://www.raylib.com
zlib License
22.95k stars 2.29k forks source link

[rcore_desktop] Upon entering fullscreen, uses original window size #3929

Open OilyFishMan opened 7 months ago

OilyFishMan commented 7 months ago

Issue description

Upon running the procedure ToggleFullscreen(), raylib reports "GetScreenWidth()" and "GetScreenHeight()" as values set before SetWindowSize(x, y). However, without ToggleFullscreen(), the original values are kept for one frame then immediately restored to correct full resolution.

Environment

Platform backend: DESKTOP (GLFW) OS: Fedora 39 x86_64 Desktop: Gnome X11 OpenGL version: 4.6 GPU: Integrated

Issue Screenshot

Screencast from 2024-04-22 18-22-46.webm Screencast from 2024-04-22 18-26-19.webm

Code Example

#include <stdio.h>
#include <raylib.h>

int main(void)
{
    InitWindow(1, 1, "Application");
    int display = GetCurrentMonitor();
    SetWindowSize(GetMonitorWidth(display), GetMonitorHeight(display));
    ToggleFullscreen();
    while (!WindowShouldClose()) {
        BeginDrawing();
        DrawRectangle(0, 0, GetMonitorWidth(display), GetMonitorHeight(display), RAYWHITE);
        printf("%d %d\n", GetScreenWidth(), GetScreenHeight());
        DrawRectangle(0, 0, GetScreenWidth() / 2, GetScreenHeight() / 2, RED);
        EndDrawing();
    }
    CloseWindow();
    return 0;
}
MagiRomanya commented 7 months ago

It seems that the actual resizing of the window contents is done in the WindowSizeCallback after the first call to EndDrawing() in the game loop. However, there is this line that prevents CORE.Window.screen.width and height to be updated in the callback: https://github.com/raysan5/raylib/blob/2e774432090db1be697d2e4e5f49ea91ca038cd3/src/platforms/rcore_desktop.c#L1625 Commenting this line solved the issue for me, but I presume is there for a reason.

OilyFishMan commented 7 months ago

That's really strange. To me this definitely doesn't seem like expected behavior.

raysan5 commented 7 months ago

Commenting this line solved the issue for me, but I presume is there for a reason.

There should probably be a comment there explaining that reason... I don't know at the moment...

archewashi commented 6 months ago

I ran the sample code under msys2 and Fedora. It worked well in msys2. GetScreenWidth() and GetScreenHeight() would return the correct full resolution at the first frame. However, the same situation like this issue occurred in Fedora.

I found the reason is when WindowSizeCallback() is called. In msys2, WindowSizeCallback() will be called after calling SetWindowSize() ( just before ToggleFullScreen()), but in Fedora, it will be called after EndDrawing(). Because of that, we can get the correct value after ToggleFullScreen() in msys2 but can't in Fedora.

raysan5 commented 6 months ago

@archewashi Thanks for the further investigation and provided details! It seems a platform-dependant issue, that's usually difficult to address...

archewashi commented 6 months ago

I guess the reason is the glfw commands to X11 are asynchronous (X11 handle commands asynchronously). XFlush may solve this problem, but it should be a bit dangerous.

Parzival-3141 commented 5 months ago

I'm running into the same issue (coincidentally with the same environment specs!), and I've found using GetRenderWidth/Height() is a suitable workaround.

SuperUserNameMan commented 4 months ago

maybe it is ok to update the values of CORE.window.screen.width/height directly into ToggleFullscreen() and ToggleBorderlessWindowed() like I proposed into this PR https://github.com/raysan5/raylib/pull/4151/files ?

archewashi commented 4 weeks ago

@raysan5 I found this PR #4074 , and logically, this issue should have been resolved. I tested it on Fedora in a VM, and no problems occurred.