So I gather from your post that you want to hook up a key so that it will exit your running OpenGL program.
You need to hook in an event handler to your GL program to handle key presses. How you do this depends on what you’re using for event processing. Tells us what you are using?
If you are using GLUT, then use glutKeyboardFunc to hook in that handler function. An example glutKeyboardFunc handler looks like this:
void keyboardCB( unsigned char key, int x, int y )
{
switch ( key )
{
case 27: // Escape key
glutDestroyWindow ( Win.id );
exit (0);
break;
}
glutPostRedisplay();
}
If you’re using raw X11 for event processing, let me know – I can post a handler for you. If other, I’m sure other folks can help out.
Now I have use the “glutKeyboardFunc(hitkey);” ,
and have wirted this function -
hitkey( unsigned char key, int x, int y )
{
switch ( key )
{
case 27: // Escape key
glutDestroyWindow ( Win.id );
exit (0);
break;
}
glutPostRedisplay();
}
But the command tells me :
amateur@amateur-desktop:~/c$ g++ -o box -lglut Box.c
Box.c: In function ‘void hitkey(unsigned char, int, int)’:
Box.c:30: error: ‘Win’ was not declared in this scope
How to do now? I think it’s not far from destination.