C++;OpenGL:调用透视会引发未定义的引用错误吗? 我使用FLUGLUT尝试用OpenGL在C++中创建我的第一个立方体。我有一个问题,每当我调用“gluPerspective”时,编译器都会抛出以下错误: build/Debug/MinGW-Windows/main.o: In function `main': C:\Users\User\Dropbox\NetBeans Workspace\Testing/main.cpp:47: undefined reference to `gluPerspective@32'

C++;OpenGL:调用透视会引发未定义的引用错误吗? 我使用FLUGLUT尝试用OpenGL在C++中创建我的第一个立方体。我有一个问题,每当我调用“gluPerspective”时,编译器都会抛出以下错误: build/Debug/MinGW-Windows/main.o: In function `main': C:\Users\User\Dropbox\NetBeans Workspace\Testing/main.cpp:47: undefined reference to `gluPerspective@32',c++,opengl,perspective,freeglut,glu,C++,Opengl,Perspective,Freeglut,Glu,我环顾四周,看看是否有人有这个问题,但什么也没有发现。所以,我想我又一次忘记了什么。下面是我调用函数的地方: ...... glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45, 1.333, 1, 1000); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); ...... 我包括freeGLUT和除该行之外的所有其他功能。我检查了文档,似乎我使用的是正确的。我不知所措。G

我环顾四周,看看是否有人有这个问题,但什么也没有发现。所以,我想我又一次忘记了什么。下面是我调用函数的地方:

......
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(45, 1.333, 1, 1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
......

我包括freeGLUT和除该行之外的所有其他功能。我检查了文档,似乎我使用的是正确的。我不知所措。

GLU透视图
已从3.1版的GLU(OpenGL帮助程序库)中删除。您是否根据仍然定义的正确库进行编译?如果没有,那么您需要编写自己的版本,并将矩阵直接传递给OpenGL

OpenGL.org在其网站上发布了以下内容(为完整起见,此处提供):


在我回答你的问题之前:为什么要使用固定函数pipline?FFP已经被弃用了。我只是想在跳入着色器和诸如此类的东西之前做一个基本的工作测试。可能是前者。后者根本没有帮助。但我使用的是最新版本的FreeGLUT和OpenGL 3.3.0。我该如何避开这个问题?@MrDoctorProfessorTyler-我搜索并找到了一个例子,但再也找不到了。(我还删除了答案中不正确的部分)。我想我只是四处搜索一下。OpenGL还有matrix类,还是我必须自己创建?@MrDoctorProfessorTyler-它还有matrix类,我已经找到了代码。谢谢!这真是一个很大的帮助:D
//matrix will receive the calculated perspective matrix.
//You would have to upload to your shader
// or use glLoadMatrixf if you aren't using shaders.
void glhPerspectivef2(float *matrix, float fovyInDegrees, float aspectRatio,
                      float znear, float zfar)
{
    float ymax, xmax;
    float temp, temp2, temp3, temp4;
    ymax = znear * tanf(fovyInDegrees * M_PI / 360.0);
    //ymin = -ymax;
    //xmin = -ymax * aspectRatio;
    xmax = ymax * aspectRatio;
    glhFrustumf2(matrix, -xmax, xmax, -ymax, ymax, znear, zfar);
}
void glhFrustumf2(float *matrix, float left, float right, float bottom, float top,
                  float znear, float zfar)
{
    float temp, temp2, temp3, temp4;
    temp = 2.0 * znear;
    temp2 = right - left;
    temp3 = top - bottom;
    temp4 = zfar - znear;
    matrix[0] = temp / temp2;
    matrix[1] = 0.0;
    matrix[2] = 0.0;
    matrix[3] = 0.0;
    matrix[4] = 0.0;
    matrix[5] = temp / temp3;
    matrix[6] = 0.0;
    matrix[7] = 0.0;
    matrix[8] = (right + left) / temp2;
    matrix[9] = (top + bottom) / temp3;
    matrix[10] = (-zfar - znear) / temp4;
    matrix[11] = -1.0;
    matrix[12] = 0.0;
    matrix[13] = 0.0;
    matrix[14] = (-temp * zfar) / temp4;
    matrix[15] = 0.0;
}