[CSC 415] Locking the Frame Rate
Andrew J. Pounds
pounds_aj at mercer.edu
Tue Mar 7 09:03:40 EST 2023
I have been experimenting with the GLFW timers and have come up with a
workable solution for locking the frame rates to a desired value
(something we must have in order to get the physics to display correctly).
First: you need to set glfwSwapInterval to ZERO. If you have it set at
one, it will lock you framerate a 60fps.
Second: you need a function to lock your framerate to a desired value.
Here is one I wrote:
void glfwLockFrameRate( float desiredFrameRate ){
double secondsToWait = 1.0 / desiredFrameRate;
double startTime = glfwGetTime();
do { /* twiddle thumbs */ }
while ( glfwGetTime() - startTime < secondsToWait );
}
Now, my home system is running at about 4000 FPS on my code, so I cannot
set the framerate above that. But if I wanted to lock the framerate at
120 FPS I could simply call
glfwLockFrameRate(120);
in the code. I put this in my main just before calling the display
function. The next trick (and this will have to wait until I get back
from my trip) is to show you how do determine what framerate you need.
--
*/Andrew J. Pounds, Ph.D./*
/Professor of Chemistry and Computer Science/
/Director of the Computational Science Program/
/Mercer University, Macon, GA 31207 (478) 301-5627/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://theochem.mercer.edu/pipermail/csc415/attachments/20230307/c0cf18f8/attachment.html>
More information about the csc415
mailing list