int main(int argc, const char* argv[])
{
glutInit(&argc, const_cast<char**>(argv));
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(640, 480);
glutCreateWindow("Sample Window");
glutDisplayFunc(render);
glutMainLoop();
return 0;
}
void keyboard(unsigned char c, int x, int y){
std::cout << "Called Keyboard";
if(c == 'a'){
exit(0);
}
}
void mouse(int button, int state, int x, int y){
std::cout << "Called Mouse";
if(button == GLUT_RIGHT_BUTTON){
exit(0);
}
}
void render(){
}
所以,我对上面的代码有疑问。键盘和鼠标功能刚刚被调用。
我希望你能设法重现这个问题。
答案 0 :(得分:6)
很简单,您忘记使用glutKeyboardFunc
和glutMouseFunc
注册它们:
int main(int argc, const char* argv[])
{
glutInit(&argc, const_cast<char**>(argv));
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(640, 480);
glutCreateWindow("Sample Window");
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutDisplayFunc(render);
glutMainLoop();
return 0;
}