glfwSwapInterval(1) fails to enable vsync?
13,524
Solution 1
Well looks like GLFW doesn't want to turn VSync on when desktop compositing is enabled. If you want VSync anyway this will work on Windows:
#ifdef _WIN32
// Turn on vertical screen sync under Windows.
// (I.e. it uses the WGL_EXT_swap_control extension)
typedef BOOL (WINAPI *PFNWGLSWAPINTERVALEXTPROC)(int interval);
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = NULL;
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
if(wglSwapIntervalEXT)
wglSwapIntervalEXT(1);
#endif
For other OSs google will help you.
Solution 2
Rebuild GLFW3 with the GLFW_USE_DWM_SWAP_INTERVAL option.
See glfw/src/config.h
The GLFW docs warn about jitter problems, but I don't see those myself.
Solution 3
Found that glfwSwapInterval needed calling again after changing between window and full screen mode, otherwise the framerate would be massive.
if (fullScreen)
{
glfwSetWindowMonitor(window, monitor, 0, 0, monitorMode->width, monitorMode->height, monitorMode->refreshRate);
// Added to fix framerate to vertical refresh //
glfwSwapInterval(1);
}
else
{
glfwSetWindowMonitor(window, NULL, 0, 0, monitorMode->width, monitorMode->height, monitorMode->refreshRate);
}
Comments
-
mwerschy almost 2 years
glfwSwapInterval(1)
doesn't seem to be working for me. If I force VSync in CCC orsetVerticalSyncEnabled(true)
in SFML my fps drops to 60, but GLFW just keeps running at 9000 fps. Am I going about this the wrong way or is GLFW bugged? -
Bram over 10 yearsThis fix did not work on my Intel HD 4600, as the proc address was 0. But configuring GLFW3 to use GLFW_USE_DWM_SWAP_INTERVAL did.
-
legends2k over 8 yearsWith release 3.1.2 this flag was removed; however, the fix is also in, so it isn't needed any longer :)