# getting rid of gluPerspective(...)

This topic is 5060 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am trying to make my camera class somewhat standalone, but at the moment it uses gluPerspective(...) to set the frustum shape (at least I think thats what it does?). This is the only reason that I need to include glut in my class, and I would like to get rid of it. Where can I find out precisely what gluPerspective does, so that I can code it myself and get rid of the gluPerspective helper method?

##### Share on other sites
gluPerspective is not a glut function, try including glu.h in your file instead of glut.h. It is declared in glu.h, and the implementation is in Glu32.lib, so as long as you include glu.h and include glu32.lib in your project, there is no reason for glut to use this function.

##### Share on other sites
well, for finding out exactly wht gluPerspective does, I'd say go to the mesa3d website. They have full code for a software version of OpenGL, Glu and GLUT,

as to a replacement, I use these 2 functions myself (thus no guarantees [8^), along with SDL.

void OpenGL_Perspective (void){	int w, h;	    //  Get width and height information from SDL    w = SDL_GetVideoSurface ()->w;    h = SDL_GetVideoSurface ()->h;    	//	Set up the opengl viewport    glViewport (0, 0, w, h);    glMatrixMode (GL_PROJECTION);    glLoadIdentity ();    glFrustum (-1.0f, 1.0f, -0.75f, 0.75f, 1.0f, 500.0f);    //	The ration of far over near (500.0 / 1.0) determines    //	the accuracy of the z-buffer.  Smaller ratios are better.    glMatrixMode(GL_MODELVIEW);}void OpenGL_Ortho (float Bound){	int w, h;		//cout << Bound << endl;	    //  Get width and height information from SDL    w = SDL_GetVideoSurface ()->w;    h = SDL_GetVideoSurface ()->h;    	//	Set up the opengl viewport    glViewport (0, 0, w, h);    glMatrixMode (GL_PROJECTION);    glLoadIdentity ();    glOrtho(-Bound, Bound, -Bound, Bound, -1, 1);    glMatrixMode(GL_MODELVIEW);}

##### Share on other sites
Quote:
 Original post by Ready4DisgluPerspective is not a glut function, try including glu.h in your file instead of glut.h. It is declared in glu.h, and the implementation is in Glu32.lib, so as long as you include glu.h and include glu32.lib in your project, there is no reason for glut to use this function.

Ok yea I guess I meant to say glu instead of glut, but the rest of my post still stands. I want to make it so I only have to include gl.h and nothing else.
thanks.

##### Share on other sites
Quote:
 Original post by lonesockwell, for finding out exactly wht gluPerspective does, I'd say go to the mesa3d website. They have full code for a software version of OpenGL, Glu and GLUT,as to a replacement, I use these 2 functions myself (thus no guarantees [8^), along with SDL.*** Source Snippet Removed ***

Thanks for the code. It seems to me that you basically just replaced the gluPerspective() call with glFrustum(). Thats the main difference between my code and yours anyway. If your code does what I want it do, then glFrustum() must do the same thing as gluPerspective(), and that doesnt seem likely, especially when I look at what parameters it takes:

void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far)

I dont see how this is defining anything other than a rectangular box, which would mean its not a perspective projection at all.

##### Share on other sites
http://www.devmaster.net/codespotlight/show.php?id=7

##### Share on other sites
Tits. Thanks!

I cant test it out till tomorrah, but if this works then its just what I was looking for.

Although, Im still confused about how glFrustum() could possibly model anything but a square frustum, in which case I dont know how perspective is being done...

##### Share on other sites
From MSDN:

The glFrustum function describes a perspective matrix that produces a perspective projection. The (left, bottom, znear) and (right, top, znear) parameters specify the points on the near clipping plane that are mapped to the lower-left and upper-right corners of the window, respectively, assuming that the eye is located at (0, 0, 0). The zfar parameter specifies the location of the far clipping plane.

Basicly you are defining the near end of the frustum, it's distance from the eye point (0,0,0) and the distance to the far plane. That's enough information to build the frustum. gluPerspective internally calls glFrustum with params derived from the ones you supply it.

##### Share on other sites
Quote:
 Original post by davepermenhttp://www.devmaster.net/codespotlight/show.php?id=7

Wow. Nice work! :)

1. 1
Rutin
45
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632999
• Total Posts
3009813
• ### Who's Online (See full list)

There are no registered users currently online

×