C++ OpenGL - How do I get delta time?
12,559
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:
Author by
romofan23
Updated on June 04, 2022Comments
-
romofan23 almost 2 years
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?