Constant game speed independent of variable FPS in OpenGL with GLUT?

后端 未结 3 559
一个人的身影
一个人的身影 2021-02-03 12:16

I\'ve been reading Koen Witters detailed article about different game loop solutions but I\'m having some problems implementing the last one with GLUT, which is the recommended

3条回答
  •  粉色の甜心
    2021-02-03 13:07

    glut is designed to be the game loop. When you call glutMainLoop(), it executes a 'for loop' with no termination condition except the exit() signal. You can implement your program kind of like you're doing now, but you need some minor changes. First, if you want to know what the FPS is, you should put that tracking into the renderScene() function, not in your update function. Naturally, your update function is being called as fast as specified by the timer and you're treating elapsedTime as a measure of time between frames. In general, that will be true because you're calling glutPostRedisplay rather slowly and glut won't try to update the screen if it doesn't need to (there's no need to redraw if the scene hasn't changed). However, there are other times that renderScene will be called. For example, if you drag something across the window. If you did that, you'd see a higher FPS (if you were properly tracking the FPS in the render function).

提交回复
热议问题