Modified how fullscreen gets toggled.
- Removed the unsetting and setting of the resize callback function. Instead of that I moved the fullscreen flag setting into a more correct place before setting the fullscreen so that this flag can be used in the callback. - In the resize callback now window size is only set when it is not fullscreen resulting in preserving the window size. - When going fullscreen the larges resolution is used so that there are no problems of the type when you minimize the window you cannot use anything else in your desktop because the resolution might be too low. If a low res effect is desired one should use render texture (this is the approach all game engines use).
This commit is contained in:
parent
6b9c5c1daf
commit
640914df2a
37
src/core.c
37
src/core.c
|
|
@ -1044,31 +1044,34 @@ void ToggleFullscreen(void)
|
||||||
if (!monitor)
|
if (!monitor)
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_WARNING, "GLFW: Failed to get monitor");
|
TRACELOG(LOG_WARNING, "GLFW: Failed to get monitor");
|
||||||
glfwSetWindowSizeCallback(CORE.Window.handle, NULL);
|
|
||||||
glfwSetWindowMonitor(CORE.Window.handle, glfwGetPrimaryMonitor(), 0, 0, CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE);
|
CORE.Window.fullscreen = false; // Toggle fullscreen flag
|
||||||
glfwSetWindowSizeCallback(CORE.Window.handle, WindowSizeCallback);
|
CORE.Window.flags &= ~FLAG_FULLSCREEN_MODE;
|
||||||
|
|
||||||
|
int modesCount = 0;
|
||||||
|
const GLFWvidmode *modes = glfwGetVideoModes(glfwGetPrimaryMonitor(), &modesCount);
|
||||||
|
glfwSetWindowMonitor(CORE.Window.handle, glfwGetPrimaryMonitor(), 0, 0, modes[modesCount - 1].width, modes[modesCount - 1].height, GLFW_DONT_CARE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CORE.Window.fullscreen = true; // Toggle fullscreen flag
|
||||||
|
CORE.Window.flags |= FLAG_FULLSCREEN_MODE;
|
||||||
|
|
||||||
const GLFWvidmode *mode = glfwGetVideoMode(monitor);
|
const GLFWvidmode *mode = glfwGetVideoMode(monitor);
|
||||||
glfwSetWindowSizeCallback(CORE.Window.handle, NULL);
|
glfwSetWindowMonitor(CORE.Window.handle, monitor, 0, 0, mode->width, mode->height, 0);
|
||||||
glfwSetWindowMonitor(CORE.Window.handle, monitor, 0, 0, CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE);
|
|
||||||
glfwSetWindowSizeCallback(CORE.Window.handle, WindowSizeCallback);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
glfwSetWindowSizeCallback(CORE.Window.handle, NULL);
|
CORE.Window.fullscreen = false; // Toggle fullscreen flag
|
||||||
|
CORE.Window.flags &= ~FLAG_FULLSCREEN_MODE;
|
||||||
|
|
||||||
glfwSetWindowMonitor(CORE.Window.handle, NULL, CORE.Window.position.x, CORE.Window.position.y, CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE);
|
glfwSetWindowMonitor(CORE.Window.handle, NULL, CORE.Window.position.x, CORE.Window.position.y, CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE);
|
||||||
glfwSetWindowSizeCallback(CORE.Window.handle, WindowSizeCallback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to enable GPU V-Sync, so frames are limited to screen refresh rate (60Hz -> 60 FPS)
|
// Try to enable GPU V-Sync, so frames are limited to screen refresh rate (60Hz -> 60 FPS)
|
||||||
// NOTE: V-Sync can be enabled by graphic driver configuration
|
// NOTE: V-Sync can be enabled by graphic driver configuration
|
||||||
if (CORE.Window.flags & FLAG_VSYNC_HINT) glfwSwapInterval(1);
|
if (CORE.Window.flags & FLAG_VSYNC_HINT) glfwSwapInterval(1);
|
||||||
|
|
||||||
CORE.Window.fullscreen = !CORE.Window.fullscreen; // Toggle fullscreen flag
|
|
||||||
CORE.Window.flags ^= FLAG_FULLSCREEN_MODE;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(PLATFORM_WEB)
|
#if defined(PLATFORM_WEB)
|
||||||
/*
|
/*
|
||||||
|
|
@ -4619,16 +4622,18 @@ static void ErrorCallback(int error, const char *description)
|
||||||
static void WindowSizeCallback(GLFWwindow *window, int width, int height)
|
static void WindowSizeCallback(GLFWwindow *window, int width, int height)
|
||||||
{
|
{
|
||||||
SetupViewport(width, height); // Reset viewport and projection matrix for new size
|
SetupViewport(width, height); // Reset viewport and projection matrix for new size
|
||||||
|
CORE.Window.currentFbo.width = width;
|
||||||
|
CORE.Window.currentFbo.height = height;
|
||||||
|
CORE.Window.resizedLastFrame = true;
|
||||||
|
|
||||||
|
if(IsWindowFullscreen())
|
||||||
|
return;
|
||||||
|
|
||||||
// Set current screen size
|
// Set current screen size
|
||||||
CORE.Window.screen.width = width;
|
CORE.Window.screen.width = width;
|
||||||
CORE.Window.screen.height = height;
|
CORE.Window.screen.height = height;
|
||||||
CORE.Window.currentFbo.width = width;
|
|
||||||
CORE.Window.currentFbo.height = height;
|
|
||||||
|
|
||||||
// NOTE: Postprocessing texture is not scaled to new size
|
// NOTE: Postprocessing texture is not scaled to new size
|
||||||
|
|
||||||
CORE.Window.resizedLastFrame = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GLFW3 WindowIconify Callback, runs when window is minimized/restored
|
// GLFW3 WindowIconify Callback, runs when window is minimized/restored
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user