glfwSwapInterval(1) fails to enable vsync?

mwerschy picture mwerschy · Apr 29, 2013 · Viewed 11.7k times · Source

glfwSwapInterval(1) doesn't seem to be working for me. If I force VSync in CCC or setVerticalSyncEnabled(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?

Answer

mwerschy picture mwerschy · Apr 30, 2013

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.