Using GLUT, moving my mouse in the display window causes the animation to increase in speed. When running at an initial 60fps, moving the mouse causes the animation to accelerate and increase to 1000fps. My data might be wrong, but there is definitely a timing issue. I've tried implementing a logic timer (force each tick to use a minimum 1/60 of a second), but I'm having mixed results.

Do you have any ideas on how to effectively control this framerate (or rather, tickrate)? Here are the resources I've been using:

Article 1 (StackOverflow)
Article 2 (GafferonGames)

Greatly appreciative.

Recommended Answers

All 2 Replies

With GLUT you cannot enforce a fixed time-step or frame rate because GLUT controls (partially) when the frames get rendered. I assume you have a rendering function which performs all the calculation for one frame and renders it. I assume also that your animation is stepping forward in "virtual time" one equal step at each render pass. This is no good when your frame-rate changes overtime. With GLUT, you cannot use the technique of waiting at the start of your render function for "1/60" of a second to have passed since the last render before rendering, because that will overwhelm GLUT who will be stacking up "ON_MOUSE_MOVE" events and that will cause you application to be "not responding" and a typical user of your game would hit ctrl-alt-delete after a few seconds of playing your game. Basically, this fixed frame rate technique is only applicable if you are not using a windowing system that triggers the rendering of your scene. Fortunately, all you need to do is instead of forcing each tick to take 1/60 of a second, you simply don't perform a tick if 1/60 seconds has not passed yet. This will give you a constant tick. However, as pointed out in the SO thread you linked to, the ideal implementation does not require a fixed frame-rate but either takes the frame-rate into account when updating the scene and hence adapts to it, or is completely independent of the frame-rate (multi-threaded, one thread renders on demand and another updates the scene at any rate that is suitable).

Thanks for the information. I think I can figure it out from there. Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.