0

不确定如何修复此错误?

这是消息...

 error C2664: 'glutSpecialFunc' : cannot convert parameter 1 from 'void (__cdecl *)(unsigned char,int,int)' to 'void (__cdecl *)(int,int,int)'   
 1>          None of the functions with this name in scope match the target type

这是我的代码....

该函数在 main 中调用。

    glutSpecialFunc(Keyboard); 

这是方法。

void Keyboard(unsigned char key, int x, int y) {

if (key == 27) {
    exit(0);
} else if (key == GLUT_KEY_DOWN) {
    drawing = 1;
} else if (key == GLUT_KEY_UP) {
    drawing = 2; 
} else if (key == GLUT_KEY_LEFT) {
    drawing = 3;
} else if (key == GLUT_KEY_RIGHT) {
    drawing = 4;
}
glutPostRedisplay();
}
4

1 回答 1

2

glutSpecialFunc(Keyboard);期望只包含 int 作为参数的函数。

所以你只需要像这样改变你的函数声明:

  void Keyboard(int key, int x, int y) {

    if (key == 27) {
        exit(0);
    } else if (key == GLUT_KEY_DOWN) {
        drawing = 1;
    } else if (key == GLUT_KEY_UP) {
        drawing = 2; 
    } else if (key == GLUT_KEY_LEFT) {
        drawing = 3;
    } else if (key == GLUT_KEY_RIGHT) {
        drawing = 4;
    }
    glutPostRedisplay();
  }

来自 openGL 文档:

过剩特殊功能

glutSpecialFunc设置当前窗口的特殊键盘回调。

用法

void glutSpecialFunc(void (*func)(int key, int x, int y));

于 2013-10-11T02:07:18.683 回答