#### Archived

This topic is now archived and is closed to further replies.

# Eliminating gluPerspective(...) call

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

## Recommended Posts

G''day ladies and gentlemen. I am making a little OpenGL game (I admit, it''s my first one... ) I now have something that mostly works. There is just one thing that bothers me. I have this ONE function call in the entire program that makes it dependant on the glu library: gluPerspective(45.0f, (GLfloat)display->width / (GLfloat)display->height, 0.1f, 2048.0f); There should be a way to implement the same functionality using regular OpenGL calls, right? I read somewhere glFrustum(...) might be relevant to this, but I couldn''t get it working (found no good examples). Anyone care to help?

##### Share on other sites
search for the mesa sourcecode, and browse there to find it''s implementation of gluPerspective..

"take a look around" - limp bizkit

##### Share on other sites

Hmm. isn''t it just (pseudocode)

myPerspective( angle, ratio, near, far ) {
v = near * tan(angle);
u = v * ratio;
glFrustrum(-u,u,-v,v,near,far);
}

Where
ratio = width/height

er .. I think ''angle'' here might be half that you''d normally pass to gluPerspective

/me afks to test theory if he has time.

btw .. use any of my wacky suggestions at your own peril

##### Share on other sites
Yep:

void MyPerspective(float fov, float aspect, float nr, float fr) {	if (use_glu) {		gluPerspective(fov,aspect,nr,fr);	} else {		float v = nr * tan((fov/2)*(pi/180));		float u = v * (aspect);		glFrustum(-u,u,-v,v,nr,fr);	}}

naive proof of concept seems to work as expected.

Note that it's tan(fov/2) and don't forget that tan() takes radians not degrees (like I did )

use_glu is (kinda obviously) a global boolean I use to swap between gluPerspective and my code at runtime.

Interestingly, when I swap to my code, any glut rendered objects (glutSolidSphere and glutSolidCube) disappear*. Presumably gluperspective does something else, too. Didn't notice any problems with lighting/texturing or anything else (tho it's a VERY simple app I tested with).

Edit: this is my dodgy code, nothing to do with glu/glut at all.

[edited by - SimbobX on November 5, 2002 9:29:53 AM]

##### Share on other sites
It works! Thanks man, I really appreciate it.

1. 1
Rutin
41
2. 2
3. 3
4. 4
5. 5

• 16
• 18
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633360
• Total Posts
3011524
• ### Who's Online (See full list)

There are no registered users currently online

×