Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Fullscreen toggling and resolution #3390

Closed
M374LX opened this issue Oct 8, 2023 · 2 comments
Closed

[core] Fullscreen toggling and resolution #3390

M374LX opened this issue Oct 8, 2023 · 2 comments

Comments

@M374LX
Copy link
Contributor

M374LX commented Oct 8, 2023

Issue description

A program using raylib might run in both windowed and fullscreen mode. For example, the window size might be 800x600 in windowed mode but the program might want use the current monitor resolution when in fullscreen.

This does not work, however:

if (IsKeyPressed(KEY_F)) {
	int monitor = GetCurrentMonitor();
	SetWindowSize(GetMonitorWidth(monitor), GetMonitorHeight(monitor));
	ToggleFullscreen();
}

The reason is because SetWindowSize() simply calls glfwSetWindowSize() without updating CORE.Window.screen.width and CORE.Window.screen.height. This causes ToggleFulscreen() to actually use the previous window size.

This is a possible workaround:

if (IsKeyPressed(KEY_F)) {
	int monitor = GetCurrentMonitor();
	SetWindowSize(GetMonitorWidth(monitor), GetMonitorHeight(monitor));
	fullscreen_toggled = true;
}


BeginDrawing();
EndDrawing();

if (fullscreen_toggled) {
	ToggleFullscreen();
	fullscreen_toggled = false;
}

The examples above show how to toggle from windowed mode to fullscreen. When doing the opposite (changing to windowed mode), this also does not work:

ToggleFullscreen();
SetWindowSize(800, 600);

Environment

Linux

Code Example

The same code examples given in #3382 (comment) apply to this issue.

@M374LX M374LX changed the title [core] Fullscreen togglling and resolution [core] Fullscreen toggling and resolution Oct 8, 2023
@SoloByte
Copy link
Contributor

I have the same issue and I am using pretty much the same workaround. (windows & macOS) So basically the window size should be updated correctly when entering fullscreen.

@raysan5
Copy link
Owner

raysan5 commented Oct 31, 2023

Just reviewed this issue and it worked as expected for me on Windows 10 x64, compiling with GCC and MSVC.

When calling SetWindowSize(), it calls glfwSetWindowSize() that automatically calls WindowSizeCallback() that starts with SetupViewport() to later update CORE.Window.screen.width and CORE.Window.screen.height with new size.

The only issue I detected is when exiting the full-screen mode calling ToggleFullscreen() again, the previous window screen size is not retrieved but it can be managed at user size and just SetWindowSize() again when exiting fullscreen mode.

@raysan5 raysan5 closed this as completed Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants