GLUT - Release keys

Started by
2 comments, last by DaRkZeAlOt 20 years ago
Hi, I made today my first steps with opengl and glut and till now i came along real good with that stuff, but now i got my first problem : I made a simple (C++) programm placing a few objects and a camera. Then i added two functions for using the keyboard (for glutKeyboardFunc and glutSpecialFunc). Works well, but everytime i press a key there's a short delay before the camera moves. I know i've to do something with the glutIgnoreKeyRepeat, glutKeyboardUpFunc and glutSpecialUpFunc functions but as more i read about as less i get it to work :-/. Maybe someone here can explain to me exactly how i can make the camera moving in one direction as long the key is pressing without delay between it. [edited by - DaRkZeAlOt on March 27, 2004 2:36:56 PM]
Advertisement
You just have to use these functions:
glutKeyboardFunc(Keyboard);
glutKeyboardUpFunc(KeyboardUp);
glutSpecialFunc(Special);
glutSpecialUpFunc(SpecialUp);
glutIgnoreKeyRepeat(1);
The *UpFunc funtions are activated when a key is relased. We also need a boolean array of 255 elements. The elements are used to store the state of the keys. So the Keyboard and KeyboardUP functions will be:

void Keyboard(unsigned char c,int x,int y){
Keys[c]=true;
//...
}

void KeyboardUp(unsigned char c,int x,int y){
Keys[c]=false;
//..
}

It''s quite simple. You have to write the Special and SpecialUP functions in a similar way. I think that, although the Special functions returns an integer value for the key, that value is never greater than 255 (but I''m not sure).



Yes, it should be so easy, but i still seem making something wrong. Thats what i'm doing during the mainfunction :

glutIgnoreKeyRepeat(1);
glutKeyboardFunc(Keyboard);
glutKeyboardUpFunc(KeyboardUp);

so far all goes well. Now i'm trying something like that to avoid the short delay between keypresses :

void KeyboardUp(unsigned char c,int x,int y)
{
Keys[c]=false;
}

void Keyboard(unsigned char c,int x,int y)
{
Keys[c]=true;
if (c == 27)
exit(0);

while(Keys[c] == true)
{
glutKeyboardUpFunc(KeyboardUp);
angle -= 0.01f;
orientMe(angle);
}
}

which ends up in an infinityloop before i can do anything. What damn thing i'm doing wrong ? Keys is a boolean array of 255 elements and angle is given too.

[edited by - DaRkZeAlOt on March 29, 2004 3:13:34 AM]
I got it ! had to check it during the scene render.

thx anyway !

This topic is closed to new replies.

Advertisement