In openGL , we draw graphics in a eternal loop while(!glfwWindowShouldClose(window)) (unless a quit event occurs ,setting the condition to false). It's said that in this render loop we need to call glclear each time a new loop performed , which 'clears background from the previous drawn to a const color'.I guess it's indicating we need to refresh framebuffer each frame . Thus each loop is a frame. However , which is controlled by a simple while(true) ( I know it's not 'true' in fact , but to some certain degree , they have the same meaning) , without stuffs like 'waitticks' or 'setframerate', which means framerate can be very very high or very very low .
-
Maybe interesting reading: [Control FPS in openGL](https://stackoverflow.com/questions/14968857/controlling-fps-limit-in-opengl-application) – zerocukor287 Dec 15 '21 at 12:23
-
Useful reading [Fix Your Timestep!](https://gafferongames.com/post/fix_your_timestep/) – Richard Critten Dec 15 '21 at 13:25
1 Answers
OpenGL doesn't control the framerate. If your loop runs 200 times per second, you get 200fps, if your loop runs only once per second, you get 1fps. The method that starts/ends frames is also not glClear
, but the method that swaps back and front buffer. This is not part of the OpenGL API, but of the windowing framework you are using. For glfw, it's the glfwSwapBuffers
method.
Note, that your famerate might be limited "automatically" by VSync. In this case, the glfwSwapBuffers
method will only return after the next VSync event which will act similar to a sleep.
In general, you can add any cap to the fps and make sure that, for example, new loop iterations are only performed after some time. Whether this is a good idea depends on the use case. For a video-player displaying a 24hz video, it absolutely makes sense to draw only every 1/24 seconds.
If you try to cap manually, make sure to use a method with a good enough resolution. sleep
is usually no precise enough, so you might want to read Precise thread sleep needed. Max 1ms error

- 21,052
- 22
- 49
- 55