Advertisement

Controlling what goes on in the glut exec loop ?

Started by December 17, 2000 02:16 PM
2 comments, last by rileyriley 23 years, 11 months ago
Hi ~ My friends and I are making a pretty simple game with open gl for our programming class, but we''re having some trouble with the program structure. We want to have an infinite loop, that the game would get run in, frame by frame. The problem is that if we use glut it seems like that structure is not an option because glut uses it''s _own_ infinite loop. So my question is, can we make our own loop and somehow maintain the event handling capabilities of glut? OR should we forget about glut and figure out a different way to get input? I''m an extreme newbie so please don''t hesitate to assume that I know nothing besides glBegin Thanks for any help, Riley
--Riley
use glutIdleFunc, then whenever glut isn''t doing anything else (most of the time) it''ll call your function.

so if you had

mainloop(){
while(1){
do stuff
}
}

do

glutIdleFunc(mainloop);
mainloop(){
do stuff
}

Advertisement
Thanks for the reply. Can I call the display method from the idle function without screwing anything up? I want to make sure that the scene gets redrawn after each run through the main loop part.

Also, is the idle function called when the user is giving input? For example, I want it so that the user can hit the arrow keys and have the game keep going. Would glut calling the key handling function stop it from calling the idle function?

Thanks again,
riley
--Riley
The right way to use GLUT is to attach your functions to the loop. If you do like Gordon suggest will GLUT not work properly because the program will always be in your loop.

You can use glutIdleFunc to make it call your function that builds a new frame and at the end ask for a post redisplay.

This topic is closed to new replies.

Advertisement