I have just learnt to write simple OpenGL programs with GLUT. I wonder if in my glutDisplayFunc I can use C functions to wait for a keyboard input. I used some functions like getch(), … between my OpenGL function calls but none of them function, although the scene showed up as I had written the code for.
In main(), you have to register a callback to the keyboard function, the prototype for which is
glutKeyboardFunc(void (*func)(unsigned char key, int x, int y));
Then write your own function keyboard, let’s say,
keyboard(unsigned char key, int x, int y)
{
switch(key) {
case ‘a’:
// call a function
break;
case ‘b’:
// call a function
break;
default:
break;
}
glutPostRedisplay(); /* this redraws the scene without
waiting for the display callback so that any changes appear
instantly */
}
Hope this helps.