views:

281

answers:

1

I'm trying to design very simple animation in OpenGL such as rotating and translating objects. In the red book, I found that using GLUT's glutIdleFunc() is okay for a simple animation.

How many times does glutIdleFunc(...) call the function in one second?

Thank you.

+1  A: 

glutIdleFunc is "continuously called when events are not being received". The update speed depends heavily on the system on which you are running, and will vary over the lifetime of the program, since it will slow down or even stop being called as events are being received.

In a typical windowed application, though, this gets called regularly enough to provide reasonable behavior. However, if you want a constant speed for rotation/translation, you'll need to implement your own timing to handle keeping the speed constant.

Reed Copsey
When a system has many CPU-bound processes and low user cpu time is available, how a custom loop could guarantee constant update speed?
Luca
Answer mentions custom timing, not custom loop. If there's not enough CPU time nothing will help. The custom timing mentioned above is meant to provide consistent drawing time when there is excess cpu time (so that application wont have unwanted speedups)
Ivan
@Reed, couldn't he use `glutTimerFunc` for a timing handler? http://www.opengl.org/resources/libraries/glut/spec3/node64.html
Elazar Leibovich
@Elazar, a forum post says that `glutTimerFunc` isn't fast enough for animation, although it should have a resolution of milliseconds, which seems to be enough (30fps = 1000/30=once in 33 ms). http://www.gamedev.net/community/forums/topic.asp?topic_id=552878
Elazar Leibovich
@Elazar: You could use this, but it's going to have a similar problem, potentially - It'll handle it at 30 fps, but for "smooth" animations on higher-end systems, you really want to have your animation be at least your refresh rate. This would work, though, if needed.
Reed Copsey
@Reed, just curious, I know nothing about 3D rendering, why does it need to be so fast. I thought that you can't really distinguish between two animations above a certain amount of fps. And I think that I don't *want* my CPU to work more than it needs to (say, electricity, for mobile devices).
Elazar Leibovich
@Elazar: It really tends to depend on the usage scenario - some people care, for some applications, and for others, it doesn't matter. It also depends on whether it's being used only for rendering, or for other purposes, etc.
Reed Copsey