1

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.

CoderTheTyler
  • 839
  • 2
  • 11
  • 30

1 Answers1

3

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;
}
ChrisF
  • 134,786
  • 31
  • 255
  • 325
  • It might be the former. The latter doesn't help at all. But I am compiling with the latest version of FreeGLUT and OpenGL 3.3.0. How do I get around this? – CoderTheTyler Feb 10 '13 at 01:07
  • I guess I'll just search around. Does OpenGL still have the matrix class or will I have to make my own? – CoderTheTyler Feb 10 '13 at 01:11
  • @MrDoctorProfessorTyler - it still has the matrix class, and I've found the code. – ChrisF Feb 10 '13 at 01:12
  • Thanks! That is a really big help :D – CoderTheTyler Feb 10 '13 at 01:13
  • 1
    gluPerspective **never** was part of OpenGL at all. It was part of GLU, a companion helper library, shipping with, but not being part of OpenGL-1.x – datenwolf Feb 10 '13 at 10:22
  • Still not correct. What happenes is that the GLU library never got updated ever since it came out. And now OpenGL outgrew it and it no longer fits. – datenwolf Feb 10 '13 at 11:32