PDA

View Full Version : limit frames per second



08-17-2005, 04:18 AM
hello all,

for a viewer for a human evacuation simulation tool for architectural structures which i am developing i want to limit the fps to a fixed number. the viewer is written in c/c++ using open gl and the glu/glut libraries. maybe someones knows a cheap line of code to limit the fps output.

greetings,
kermit

ZbuffeR
08-17-2005, 04:31 AM
dirty pseudocode :


render() {
/* actual render code goes here */
glFlush();
while (getCurrentTime() < lastTime +delta) {
sleep(10);
}
lastTime=lastTime+delta;
SwapBuffers();
}Maybe better, call render() in a timer set to your desired delta (and remove the glFlush).

08-17-2005, 04:38 AM
thx for the fast answer.
of a "sleep" i have thinked allready myself, just wondering if there isn't some nice thing build in in GLU/GLUT to limit fps.

memfr0b
08-17-2005, 06:03 AM
If you already use glut, you can try something like


void timer(int) {
glutPostRedisplay();
glutTimerFunc(1000/DESIRED_FPS, timer, 0);
}

08-18-2005, 03:53 AM
thx for the answer, will try it later.