我试图通过按键盘上的一个键在执行期间暂停我的 GLUT 程序。它似乎无法识别我的条目。以下是我的代码的相关部分:
static bool paused = false;
void handleKeypress(unsigned char key, //The key that was pressed
int x, int y) { //The current mouse coordinates
switch (key) {
case 27: //Escape key
exit(0); //Exit the program
case 'p':
paused = !paused;
break;
}
}
int main(int argc, char** argv) {
//Initialize GLUT
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(600, 400); //Set the window size
//Create the window
glutCreateWindow("Fractals in Motion");
initRendering(); //Initialize rendering
//Set handler functions for drawing, keypresses, and window resizes
if(!paused)
{
glutDisplayFunc(drawScene); //drawScene draws everything does the real work
glutTimerFunc(10, update, 0); //Add a timer
}
//glutKeyboardFunc(handleKeypress);
glutReshapeFunc(handleResize);
glutMainLoop(); //Start the main loop. glutMainLoop doesn't return.
return 0; //This line is never reached
}
实际上,我从这个非常愿意编写的教程中得到了这段代码的骨架:
http://www.videotutorialsrock.com/opengl_tutorial/basic_shapes/home.php
但是,当我按下“p”键时,我似乎无法让程序暂停。如果您有更好的方法,请告诉我!