limit frames per second

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

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).

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.

If you already use glut, you can try something like

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

thx for the answer, will try it later.