PDA

View Full Version : how execute instructions when there is no events/no key pressed ?



airseb
05-28-2003, 09:03 AM
hi !
i have a problem, i would like to execute instructions when no key are pressed.
What library can i use with open gl and what instruction make it ?
i have tried to use glutIdleFunc () but i don't find where put this function.
i have done this with it but it works only when i press a key and not when no key are pressed : (thanks for your help)



void keyboard (unsigned char key, int x, int y)
{
switch (key)
{
case 'r' :
case 'R' :
nb_transformation++ ;
r = 5.0;
glutPostRedisplay () ; //réexécute la fonction display
break ;
default :
glutIdleFunc(withoutEvents) ;
break ;
}
}

nexusone
05-28-2003, 09:40 AM
On glutIdleFunc, you don't call it from the keyboard unless you are turning it on/off.

The glutIdleFunc is called with there is no glut event's like keyboard, repostdisplay, etc.

I put the glutIdleFunc in the main function, see examples on my website: www.angelfire.com/linux/nexusone/ (http://www.angelfire.com/linux/nexusone/)


alternative way in the keyboard:

case 'a':
case 'A':
if ( animation ) // if animation ON, turn it off
{
glutIdleFunc(); // stop Idle func
animation = 0;
}else{
glutIdleFunc(my_idlefunc); // Start Idle function
animation = 1; animation ON
}
break;


Originally posted by airseb:
hi !
i have a problem, i would like to execute instructions when no key are pressed.
What library can i use with open gl and what instruction make it ?
i have tried to use glutIdleFunc () but i don't find where put this function.
i have done this with it but it works only when i press a key and not when no key are pressed : (thanks for your help)



void keyboard (unsigned char key, int x, int y)
{
switch (key)
{
case 'r' :
case 'R' :
nb_transformation++ ;
r = 5.0;
glutPostRedisplay () ; //réexécute la fonction display
break ;
default :
glutIdleFunc(withoutEvents) ;
break ;
}
}

Rob Fletcher
05-29-2003, 02:47 AM
The idle loop is there exactly for what you want to do. Basically when the rest of your program is doing nothing, then control is passed to the function you specify in the
glutIdleFunc() call.

Set it up in your main() after the various initialisations.

myIdle()
{
x++;
y++;
.... or whatever you want to do ...
}

int main(...)
{
... init codes ...
glutIdleFunc(myIdle);
glutMainLoop();
return 0;
}

To stop the idle function running, simply call glutIdleFunc(NULL) at some time, e.g. in a keyboard function as per the above example!

Hope this helps,

Rob