key input using glut
When I use glut keyboard function, if I hold a key on the keyboard it will be repetitive(just like in a text editor). For a game, this is not very good because movement of the object will be jerky. Is there a way using glut that I can get something like ''key down'' and ''key up'' event or a continuous key input?
I''m new with glut. Before this I use NeHe method for keyboard input and it''s realy good for a game.
Look at these two functions:
void pressKey(int key, int x, int y) {
switch (key) {
case GLUT_KEY_LEFT :
break;
case GLUT_KEY_RIGHT :
break;
case GLUT_KEY_UP :
break;
case GLUT_KEY_DOWN :
break;
}
}
void releaseKey(int key, int x, int y) {
switch (key) {
case GLUT_KEY_LEFT :
break;
case GLUT_KEY_RIGHT :
break;
case GLUT_KEY_UP :
break;
case GLUT_KEY_DOWN :
break;
}
}
And use these in your main()
glutIgnoreKeyRepeat(1); //Any non-zero value will enable this.
glutSpecialFunc(pressKey);
glutSpecialUpFunc(releaseKey);
edit:
Note that glutIgnoreKeyRepeat() works as of GLUT 3.7 since the introduction of GameGLUT iirc.
[edited by - Juicy on December 13, 2002 6:51:19 AM]
void pressKey(int key, int x, int y) {
switch (key) {
case GLUT_KEY_LEFT :
break;
case GLUT_KEY_RIGHT :
break;
case GLUT_KEY_UP :
break;
case GLUT_KEY_DOWN :
break;
}
}
void releaseKey(int key, int x, int y) {
switch (key) {
case GLUT_KEY_LEFT :
break;
case GLUT_KEY_RIGHT :
break;
case GLUT_KEY_UP :
break;
case GLUT_KEY_DOWN :
break;
}
}
And use these in your main()
glutIgnoreKeyRepeat(1); //Any non-zero value will enable this.
glutSpecialFunc(pressKey);
glutSpecialUpFunc(releaseKey);
edit:
Note that glutIgnoreKeyRepeat() works as of GLUT 3.7 since the introduction of GameGLUT iirc.
[edited by - Juicy on December 13, 2002 6:51:19 AM]
I like pie! - weebl.
Oneiric - Another graphics engine in the works.
Oneiric - Another graphics engine in the works.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement