void special(int key, int x, int y)
{
char *name;
switch (key) {
case GLUT_KEY_F1:
name = "F1";
break;
case GLUT_KEY_F2:
name = "F2";
break;
case GLUT_KEY_F3:
name = "F3";
break;
case GLUT_KEY_F4:
name = "F4";
break;
case GLUT_KEY_F5:
name = "F5";
break;
case GLUT_KEY_F6:
name = "F6";
break;
case GLUT_KEY_LEFT:
name = "Left";
break;
case GLUT_KEY_UP:
name = "Up";
break;
case GLUT_KEY_RIGHT:
name = "Right";
break;
case GLUT_KEY_DOWN:
name = "Down";
break;
case GLUT_KEY_PAGE_UP:
name = "Page up";
break;
case GLUT_KEY_PAGE_DOWN:
name = "Page down";
break;
case GLUT_KEY_HOME:
name = "Home";
break;
case GLUT_KEY_END:
name = "End";
break;
case GLUT_KEY_INSERT:
name = "Insert";
break;
default:
name = "UNKONW";
break;
}
printf("special: %s %d,%d\n", name, x, y);
}
static void Key(unsigned char key, int x, int y)
{
switch (key) {
case 't':
printf("t\n");
break;
case 27:
printf("exit\n");
exit(0);
}
}
void mouse(int button, int state, int x, int y)
{
switch (button) {
case GLUT_LEFT_BUTTON:
if (state == GLUT_DOWN)
printf("GLUT_LEFT_BUTTON\n");
break;
case GLUT_MIDDLE_BUTTON:
if (state == GLUT_DOWN)
printf("GLUT_MIDDLE_BUTTON\n");
break;
case GLUT_RIGHT_BUTTON:
if (state == GLUT_DOWN)
printf("GLUT_RIGHT_BUTTON\n");
break;
default:
break;
}
}
以上函数调用方法为:
glutKeyboardFunc(Key);
glutSpecialFunc(special);
glutMouseFunc(mouse);
转载于:https://www.cnblogs.com/penny1141/archive/2012/04/25/2470109.html
相关资源:最全opengl鼠标键盘控制事件
转载请注明原文地址: https://win8.8miu.com/read-1499992.html