2

I'm currently programming an OpenGL game in C++ using GLUT, GLEW, SDL, and GLM. I'm trying to rotate a cube at a consistent speed, but, unfortunately, my game is frame-rate dependent. Is there any way I could get the delta time?

romofan23
  • 69
  • 2
  • 2
  • 11

1 Answers1

4

glutGet(GLUT_ELAPSED_TIME) is a possibility if you are using GLUT and milliseconds are enough:

void idle(void) {
    int t;
    /* Delta time in seconds. */
    float dt;
    t = glutGet(GLUT_ELAPSED_TIME);
    dt = (t - old_t) / 1000.0;
    old_t = t;
    glutPostRedisplay();
}

void init(void) {
    old_t = glutGet(GLUT_ELAPSED_TIME);
}

And there are nanosecond clocks in C11 and C++11 if you have those:

Community
  • 1
  • 1
Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985