Question

I am using FreeGLUT to try and create my first cube in C++ with OpenGL. I have an issue that whenever I call "gluPerspective", the compiler throws this error:

build/Debug/MinGW-Windows/main.o: In function `main':
C:\Users\User\Dropbox\NetBeans Workspace\Testing/main.cpp:47: undefined reference to `gluPerspective@32'

I have looked around to see if anyone has had this problem and found nothing. So, I think I am being oblivious to something yet again. Here is where I call the function:

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

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

I include freeGLUT and everything else works except that line. I checked the documentation , and it seems as though I am using it correctly. I am at a loss.

Was it helpful?

Solution

gluPerspective was removed from GLU (the OpenGL helper library) at version 3.1. Are you compiling against the correct library that still has it defined? If not then you will need to write your own version and pass the matrix direct to OpenGL.

OpenGL.org has the gluPerspective code on it's website (presented here for completeness):

//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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top