Eliminating gluPerspective(...) call
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?
search for the mesa sourcecode, and browse there to find it''s implementation of gluPerspective..
"take a look around" - limp bizkit
www.google.com
"take a look around" - limp bizkit
www.google.com
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
Yep:
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]
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement