Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glfwSwapInterval(1) fails to enable vsync?

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?

like image 963
mwerschy Avatar asked Apr 29 '13 18:04

mwerschy


People also ask

What is glfwSwapInterval?

glfwSwapInterval (int interval) Sets the swap interval for the current context.

How do I turn off vsync on Glfw?

Once you've made your GL context current via glfwMakeContextCurrent() you can use glfwSwapInterval(0) to request that vsync be disabled: int main( int, char** ) { GLFWwindow* window; glfwInit(); window = glfwCreateWindow( 640, 480, "GLFW", NULL, NULL ); glfwMakeContextCurrent( window ); glfwSwapInterval( 0 ); ...


1 Answers

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.

like image 68
mwerschy Avatar answered Sep 27 '22 19:09

mwerschy