PDA

View Full Version : glPerspective



Muerte
10-04-2000, 10:27 AM
Keep in mind i'm new to OpenGL, so be soft on the responses;
I'm currently using the MingW compiler for my projects, although it might not be of any relevance to my problem- I receive an "undefined reference to glPerspective@32" error whenever trying to compile a project using the glPerspective() function,eg.
glMatrixMode(GL_PERSPECTIVE);
glPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
Any suggestions? Logical fixes?
Thanks,
-Brian

DFrey
10-04-2000, 11:52 AM
You sure that is not supposed to be gluPerspective instead of glPerspective? Or is that just an error in your message?

Bob
10-04-2000, 10:58 PM
Yepp, you forgot a 'u' in your call to gluPerspective. You also need to #include <GL/glu.h> and add glu32.lib to your project.

Eric
10-05-2000, 01:21 AM
Actually, there is another problem (and I am surprised that you did not spot it out, Bob !).

You should use :

glMatrixMode(GL_MODELVIEW); // Not GL_PERSPECTIVE ! //
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

Bob
10-05-2000, 02:07 AM
GL_MODELVIEW Huh? You sure you don't mean GL_PROJECTION? http://www.opengl.org/discussion_boards/ubb/biggrin.gif

Projections is suppose to reside in the projection matrix, and translations in the modelview.

But look at the error message in the first post, the problem is the perspective function. But you are right, GL_PERSPECTIVE is wrong.

p.s. And I addmit, I didn't noticed it... *whistle*

Eric
10-05-2000, 02:56 AM
Arf' yes, I meant GL_PROJECTION !

Sorry, Muerte, I do not want to confuse you...

So, the definitive code is :

glMatrixMode(GL_PROJECTION); // Not GL_PERSPECTIVE nor GL_MODELVIEW !!! //
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

1,2,3... Sold !

Best Regards.

Eric

P.S. : Thanks Bob !

Muerte
10-05-2000, 08:30 AM
Lol, yeah i'm sorry i made alot of dumb mistakes in that code which i posted originally. It wasn't directly coppied and pasted from my source code, i typed it out again and had mistakes. The exact code is:
/*some initialization stuff up here*/
glLoadIdentity();
glViewport(100,100,600,600);
glMatrixMode(GL_PROJECTION);
glShadeModel(GL_SMOOTH);
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
/*rest of stuff down here */

and this seems to generate the error which i stated in the original message. Again, sorry about the mistakes before, next time i'll copy/paste directly for perfection. http://www.opengl.org/discussion_boards/ubb/wink.gif
-Brian

DFrey
10-05-2000, 09:08 AM
Made another mistake and put GL_PROJECTION instead of GL_PERSPECTIVE, but that isn't the problem causing the error. http://www.opengl.org/discussion_boards/ubb/biggrin.gif
Looks like you simply need to link in the glu library when building the executable.

[This message has been edited by DFrey (edited 10-05-2000).]

Muerte
10-05-2000, 09:37 AM
Thanks, DFrey, and is there a specific way I can link the library from within the source code?

DFrey
10-05-2000, 10:19 AM
Sorry, I don't know how to do it with the MingW compiler (never heard of it till you mentioned it). But my guess would be to use the command line option -lglu32 to make it link in the glu32 library.

[This message has been edited by DFrey (edited 10-05-2000).]

Bob
10-05-2000, 10:25 AM
But... in some way you must have managed to get the OpenGL library file into your project/commandline/makefile/whateveryoumightbeusing. Otherwise you should have gotten similar error messages for each call to the core OpenGL (those with 'gl' prefix). So I guess you should do about the same with the GLU library file too.

Muerte
10-05-2000, 11:08 AM
er... Bob- Lets just put it this way- i've included the 3 libraries "Gl.h", "glaux.h", and "glu.h" to my project. From the responses i'm getting, i'm quite sure this has something to do with the compiler i'm using now-MingWin. =\
-Brian

tdavie
10-05-2000, 11:24 AM
gl.h, glu.h and glut.h are not the libraries, they are just the header files. All these contain is prototype statements for the functions, the libraries contain the actual functions (or at least masks to them because the DLLs contain the actual functions). Your compiler will have one of two ways of doing this - either you will have a nice sofficticated compiler and you will have a project window where you can add all the source files and librarys your program needs. OR you need a make file which tells the compiler exactly what to do when in which case you need to add the command line (it was somewhere earlier on in the discussion) to the make file, to make sure that the library is added.

You probably need these 3 libraries:
OpenGLLibraryStub,
OpenGLMemoryStub and
OpenGLUtilityStub.
for glut you will also need glut.lib.

Failing that get a decent compiler like Visual C++, Borland C++ or Metrowerks Codewarrior.

Muerte
10-06-2000, 07:09 AM
Heh, ok i got it working now. Thanks to ..*drum roll*... DFrey. All i needed was the glu32 library, everything else was already linked. Thanks to everyone else too, though. http://www.opengl.org/discussion_boards/ubb/wink.gif
-Brian