c++ - OpenGL glutKeyboardFunc 错误

标签 c++ xcode opengl

我正在尝试在 OpenGL 中使用 glutKeyboardFunc。但是当我在 main 中使用这个函数时,它给我一个错误,No matching function for call to 'glutKeyboardFunc'。为什么会这样?

#include<GLUT/glut.h>
#include<OpenGL/OpenGL.h>
#include<iostream>

using namespace std;

static void display(){
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(-1.0, 1.0, -1.0, 1.0);
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(0.6, 1, 0.4);
    glFlush();
}

void mykeypressed(char key, int x,int y){

}

int main(int argc, char * argv[]){
    glutInit(&argc, argv);
    glutInitWindowPosition(300, 300);
    glutInitWindowSize(500, 500);
    glutCreateWindow("ps4_1");
    glutDisplayFunc(display);
    glutKeyboardFunc(mykeypressed);
    glutTimerFunc(10000, exit, 0);
    glutMainLoop();
    return 0;
}

最佳答案

glutKeyboardFunc的签名是

void glutKeyboardFunc(void (*func)(unsigned char key, int x, int y));
//                                 ^^^^^^^^

mykeypressed() 的第一个参数是 char,而不是 unsigned char。这两种类型是不同的。

关于c++ - OpenGL glutKeyboardFunc 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25439526/

相关文章:

c++ - 将列表初始化对插入 std::map

c++ - 为什么 lldb pretty-print 不适用于 MacOS 上的 GNU GCC 编译程序?

c# - 在 OpenGL 中使用纹理图集计算单个图 block 的纹理坐标

swift - 在 mapView 中搜索特定的注释

xcode - 如何填充 TableView 而不是 TableView Controller ?

c++ - 图片显示错误

java - 在 libGDX 中,3D 对象是相互透视的

c++ - C++中的双向异步通信

c++ - 是什么导致我的 2D Perlin 噪声中出现这些伪像?

ios - 苹果因崩溃而拒绝了该应用,无法对其进行复制