fixes for switching full-screen and v-sync
This commit is contained in:
parent
0a2177b4bc
commit
1a956208e2
26
src/core.c
26
src/core.c
|
|
@ -311,6 +311,7 @@ static unsigned int displayWidth, displayHeight;// Display width and height (mon
|
|||
static int screenWidth, screenHeight; // Screen width and height (used render area)
|
||||
static int renderWidth, renderHeight; // Framebuffer width and height (render area, including black bars if required)
|
||||
static int currentWidth, currentHeight; // Current render width and height, it could change on BeginTextureMode()
|
||||
static int windowLeftPos, windowTopPos;
|
||||
static int renderOffsetX = 0; // Offset X from render area (must be divided by 2)
|
||||
static int renderOffsetY = 0; // Offset Y from render area (must be divided by 2)
|
||||
static bool fullscreen = false; // Fullscreen mode (useful only for PLATFORM_DESKTOP)
|
||||
|
|
@ -853,8 +854,21 @@ void ToggleFullscreen(void)
|
|||
fullscreen = !fullscreen; // Toggle fullscreen flag
|
||||
|
||||
// NOTE: glfwSetWindowMonitor() doesn't work properly (bugs)
|
||||
if (fullscreen) glfwSetWindowMonitor(window, glfwGetPrimaryMonitor(), 0, 0, screenWidth, screenHeight, GLFW_DONT_CARE);
|
||||
else glfwSetWindowMonitor(window, NULL, 0, 0, screenWidth, screenHeight, GLFW_DONT_CARE);
|
||||
if (fullscreen) {
|
||||
glfwGetWindowPos(window, &windowLeftPos, &windowTopPos);
|
||||
|
||||
GLFWmonitor *monitor = glfwGetPrimaryMonitor();
|
||||
if (!monitor)
|
||||
{
|
||||
TraceLog(LOG_WARNING, "Failed to get monitor");
|
||||
glfwSetWindowMonitor(window, glfwGetPrimaryMonitor(), 0, 0, screenWidth, screenHeight, GLFW_DONT_CARE);
|
||||
return;
|
||||
}
|
||||
|
||||
const GLFWvidmode *mode = glfwGetVideoMode(monitor);
|
||||
glfwSetWindowMonitor(window, glfwGetPrimaryMonitor(), 0, 0, screenWidth, screenHeight, mode->refreshRate);
|
||||
}
|
||||
else glfwSetWindowMonitor(window, NULL, windowLeftPos, windowTopPos, screenWidth, screenHeight, GLFW_DONT_CARE);
|
||||
#endif
|
||||
|
||||
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
|
||||
|
|
@ -2672,6 +2686,13 @@ static bool InitGraphicsDevice(int width, int height)
|
|||
|
||||
if (fullscreen)
|
||||
{
|
||||
// remember center for switchinging from fullscreen to window
|
||||
windowLeftPos = displayWidth/2 - screenWidth/2;
|
||||
windowTopPos = displayHeight/2 - screenHeight/2;
|
||||
|
||||
if (windowLeftPos < 0) windowLeftPos = 0;
|
||||
if (windowTopPos < 0) windowTopPos = 0;
|
||||
|
||||
// Obtain recommended displayWidth/displayHeight from a valid videomode for the monitor
|
||||
int count = 0;
|
||||
const GLFWvidmode *modes = glfwGetVideoModes(glfwGetPrimaryMonitor(), &count);
|
||||
|
|
@ -3768,6 +3789,7 @@ static void PollInputEvents(void)
|
|||
static void SwapBuffers(void)
|
||||
{
|
||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
||||
glfwSwapInterval((configFlags & FLAG_VSYNC_HINT) != 0 ? 1 : 0);
|
||||
glfwSwapBuffers(window);
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user