So basically, I've been having trouble getting keyboard functions to work with glut. I've pasted the code that is relevant to my problem:
[cpp]
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(900, 450);
glutInitWindowPosition(100, 100);
glutCreateWindow("GLPong - By Darkness_2");
glutDisplayFunc(display);
glutIdleFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyPressed);
glutKeyboardUpFunc(keyUp);
glutSpecialFunc(keySpecial);
glutSpecialUpFunc(keySpecialUp);
glutMainLoop();
return 0;
}[/cpp]
[cpp]
bool* keyStates = new bool[256];
bool* keySpecialStates = new bool[256];
void keyOperations ()
{
if (keyStates['g'])
drawGrid();
}
void keyPressed(unsigned char key, int x, int y)
{
cout<<"KeyPressed"<<endl;
keyStates[key] = true;
}
void keyUp(unsigned char key, int x, int y)
{
cout<<"KeyUp"<<endl;
keyStates[key] = false;
}
void keySpecial(int key, int x, int y)
{
cout<<"KeySpecial"<<endl;
keySpecialStates[key] = true;
}
void keySpecialUp(int key, int x, int y)
{
cout<<"KeySpecialUp"<<endl;
keySpecialStates[key] = false;
}[/cpp]
And keyOperations is called every time display runs. Anyways, what happens is I've noticed that keyPressed or any other key related function never runs! Even when pressing tons of keys. It's really weird. That's why I put the couts in there because I wanted to see when each function was running. Anyone have any thoughts here?
I got suspicious something was up when my drawGrid function would never run.
Sorry, you need to Log In to post a reply to this thread.