Sign in to follow this  
BloodLust666 (dupe)

glFrustum and gluPerspective not working

Recommended Posts

I originally had glOrtho because I had a 2D engine but now i'm turning it into 3D and i'm having some trouble with the 3D "camera". when calling glOrtho, i would pass something like glOrtho(-screen.X, screen.X, -screen.Y, screen.Y, near, far); the camera was center screen and everything was fine. but now, just to test out the new camera, i put a sphere (not a glutsphere, i made the sphere myself with vertices) with a radius of 20 units and placed it at 0,0,0 and moved the camera back to 0,0,50 . Then i tried calling both: glFrustum(-screen.X, screen.X, -screen.Y, screen.Y, near, far); and gluPerspective(90.0, screen.X / screen.Y, near, far) but nothing shows up... when i have the exact same scenario though and call glOrtho, my sphere appears center screen Am i calling those wrong possibly? or do I need some other glFunction as well?

Share this post


Link to post
Share on other sites
Lord_Evil    680
What are your values for near and far?

IIRC the initial look at vector (the direction in which the camera is facing) is (0,0,1) so if you move the camera to position (0,0,50) the sphere would end up BEHIND the camera. Tried (0,0,-50) already?

Also, just use one of both. I don't know of gluPerspective but the docs say that glFrustum multiplies the current matrix with the frustum matrix. So in your case you'd get glFrustum * gluPerspective.

Share this post


Link to post
Share on other sites
near is 1.0 and far is 1000.0

yep... i've tried moving the camera both ways; thought the same thing too, that the camera might have been pointing in the wrong direction.

I know to use only one, i searched for glFrustum and gluPerspective in these forums and i saw a lot saying that and the gluPerspective calls glFrustum and it's just a different interface.

I'm thinking that maybe the numbers i'm using are making my sphere not in the frustum at all, for some weird reason: here are the actual values i'm using with the code


// set up camera
glViewport(0, 0, 640, 480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-320.0, 320.0,
-240.0, 240.0,
1.0, 1000.0);

// position camera
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(-Rotation.X, 1.0f, 0.0f, 0.0f);
glRotatef(-Rotation.Y, 0.0f, 1.0f, 0.0f);
glRotatef(-Rotation.Z, 0.0f, 0.0f, 1.0f);
glTranslatef(0.0, 0.0, -50.0);

// DrawScene
// ...





what makes that weird is even though everything looks right, nothing shows up, but when i replace glFrustum with glOrtho, my sphere shows up...

Note: All three components of Rotation are 0.0, those are properties of the camera in the engine.

Share this post


Link to post
Share on other sites
Lord_Evil    680
I checked glFrustum once again and I assume the values for left, right etc. are too big, i.e. the frustum might be too big and thus your sphere could be too small to be noticed (your fov is almost 180 degrees).

Try gluPerspective with an angle of 60 and aspect = w/h.

Share this post


Link to post
Share on other sites
what about the fov? what's that usually set to? i'm guessing having a smaller fov will simulate a "widescreen" effect, right? has anyone ever used it for that purpose?

what about a zooming effect? is that just scaling the fov and aspect ratio by a constant depending on how much "zoom" you want?

Share this post


Link to post
Share on other sites
Lord_Evil    680
AFAIK the normal human fov is 120 degrees, so since in gluPerspective you provide the half fov (the angle from the center to the sides) you'd provide 60 for getting a 120 degree fov.

Zooming in would just require to reduce the fov, zooming out would mean increasing the fov. As the fov is getting smaller the part of the world that lies in the frustum and thus is visible on screen is getting smaller and so the dislayed objects cover a bigger area on screen and appear zoomed. With increasing fov it's the other way round.

Just keep in mind that providing 90 degrees means a 180 degree fov.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this