-
A quick GLUT question
I'm getting into GL/GLUT now - I've been using SDL and Allegro for a while and I thought "hey, why not make my own game engine?" I know what you're thinking... what a tool, why doesn't he just stick with SDL. Well, it's a learning experience, ok? So don't give me any lip about that.
But I did have a question concerning something I found I could do easily in SDL, and that is giving me some difficulty right now. I'm trying to get the window to update and redraw every 60 frames per second (or every vsync, at least). How does one go about doing that within glutMainLoop()?
-
I'd have to double check to be sure, but I thought you just registered a draw function and that got called every go-round of the mainLoop.
-
There's the display callback but that is only called when the window manager says the screen needs to be redrawn, like on a resize or when you move the window. And the idle callback is called every go-round but I'm looking for a smooth framerate and not let's-go-as-fast-as-we-can. Snake would be a very difficult game to play at 400 fps.
-
Some searching led to the manual here which suggests glutTimerFunc.
(EDIT: I suppose I should say I suggest glutTimerFunc, since the manual isn't necessarily suggesting anything.)
-
Oh, neat, thanks.
So I'll call a glutPostRedisplay in the timer and set the timer again to 1000/60.
Or rather set the timer first, then call for a redisplay.