fixes for switching full-screen and v-sync

This commit is contained in:
MasterZean 2019-09-11 16:39:40 +03:00
parent 0a2177b4bc
commit 1a956208e2

View File

@ -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 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 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 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 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 int renderOffsetY = 0; // Offset Y from render area (must be divided by 2)
static bool fullscreen = false; // Fullscreen mode (useful only for PLATFORM_DESKTOP) static bool fullscreen = false; // Fullscreen mode (useful only for PLATFORM_DESKTOP)
@ -853,8 +854,21 @@ void ToggleFullscreen(void)
fullscreen = !fullscreen; // Toggle fullscreen flag fullscreen = !fullscreen; // Toggle fullscreen flag
// NOTE: glfwSetWindowMonitor() doesn't work properly (bugs) // NOTE: glfwSetWindowMonitor() doesn't work properly (bugs)
if (fullscreen) glfwSetWindowMonitor(window, glfwGetPrimaryMonitor(), 0, 0, screenWidth, screenHeight, GLFW_DONT_CARE); if (fullscreen) {
else glfwSetWindowMonitor(window, NULL, 0, 0, screenWidth, screenHeight, GLFW_DONT_CARE); 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 #endif
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) #if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
@ -2672,6 +2686,13 @@ static bool InitGraphicsDevice(int width, int height)
if (fullscreen) 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 // Obtain recommended displayWidth/displayHeight from a valid videomode for the monitor
int count = 0; int count = 0;
const GLFWvidmode *modes = glfwGetVideoModes(glfwGetPrimaryMonitor(), &count); const GLFWvidmode *modes = glfwGetVideoModes(glfwGetPrimaryMonitor(), &count);
@ -3768,6 +3789,7 @@ static void PollInputEvents(void)
static void SwapBuffers(void) static void SwapBuffers(void)
{ {
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
glfwSwapInterval((configFlags & FLAG_VSYNC_HINT) != 0 ? 1 : 0);
glfwSwapBuffers(window); glfwSwapBuffers(window);
#endif #endif