I'm writting a game with OGL / GLFW in c++.
My game is always running at 60 fps and without any screen tearing. After doing some research, it seems that the glfwSwapInterval()
function should be able to enable/disable V-sync or the 60fps cap.
However, no matter the value I pass to the function, the framerate stays locked at 60 and there is no tearing whatsoever. I have also checked the compositor settings on linux and the nvidia panel, and they take no effect.
This is a common thing I assume, is there a way to get around this fps cap?
Is there a way to remove 60 fps cap in GLFW?
The easiest way is to use single buffering instead of double buffering. Since at single buffering is always use the same buffer there is no buffer swap and no "vsync".
Use the glfwWindowHint
to disable double buffering:
glfwWindowHint( GLFW_DOUBLEBUFFER, GL_FALSE );
GLFWwindow *wnd = glfwCreateWindow( w, h, "OGL window", nullptr, nullptr );
Note, when you use singel buffering, then you have to explicite force execution of the GL commands by (glFlush
), instead of the buffer swap (glfwSwapBuffers
).
Another possibility is to set the number of screen updates to wait from the time glfwSwapBuffers
was called before swapping the buffers to 0. This can be done by glfwSwapInterval
, after making the OpenGL context current (glfwMakeContextCurrent
):
glfwMakeContextCurrent( wnd );
glfwSwapInterval( 0 );
But note, whether this solution works or not, may depend on the hardware and the driver.