Jump to content
  • Advertisement


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.

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
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 this post

Link to post
Share on other sites

Hmm. isn''t it just (pseudocode)

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

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 this post

Link to post
Share on other sites

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

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 this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!