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?
Asked
Active
Viewed 1.6k times
2
-
1http://gamedev.stackexchange.com/questions/13008/how-to-get-and-use-delta-time – Ivarpoiss Mar 16 '14 at 04:46
-
1Also see this http://stackoverflow.com/questions/1487695/c-cross-platform-high-resolution-timer – Ivarpoiss Mar 16 '14 at 04:49
-
I've tried this, but it doesn't work. – romofan23 Mar 16 '14 at 04:52
-
1If you do not show at least some code there is not a lot of potential for help here... saying you tried something but that it did not work is not opening up discussion for possible issues with your attempted implementation. If you could edit your question to include some code showing what you tried, that would be ideal. – Andon M. Coleman Mar 16 '14 at 18:42
-
1What version of C++? C++11 has `
` – Basile Starynkevitch Mar 19 '16 at 11:13
1 Answers
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