How to schedule function in GLUT
I have some function which are calling from main function.Below is code.
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_开发者_StackOverflow社区DOUBLE);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow("Game for Gamers");
glutDisplayFunc(display_func);
glutKeyboardFunc(keyboard);
glutSpecialFunc(special);
glutTimerFunc(50,refreshcheck,0);
glutIdleFunc (animate);
glutReshapeFunc (reshape);
glutMainLoop();
return 0;
}
Here "refreshcheck" is calling first i want to call "refreshcheck" function after execution of "display_func" function.How will schedule it.I want to call "display_func" execute function first when game loaded in memory before "refreshcheck" function, it is not necessary to call "refreshcheck" after "display_func" when game is running, but for first time this is important.
You should not be, in general, creating objects inside displayFunc (as dark_charlie correctly pointed out). But that is just bad practice, nothing more.
If you require collision detection, you should make it synchronous to rendering, i.e. call it from your displayFunc (at it's end).
I guess the reason you want to use timer is to have constant step physics. This is usually done the other way, using gettimeofday() (or GetTickCount() on windows) to get the time, and based on the time elapsed between the frames, the physics is called N times. That will get you far better precision than using GLUT timers, as timers are only precise up to 10s of milliseconds, which can be a lot when dealing with fast moving objects, leading to stuttering.
精彩评论