glFrustum and gluPerspective not working

Started by
7 comments, last by Lord_Evil 17 years, 1 month ago
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?
Eddie RiveronSoftware EngineerCreator of 3D Wrath EngineWebsite soon!
Advertisement
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.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
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 cameraglViewport(0, 0, 640, 480);glMatrixMode(GL_PROJECTION);glLoadIdentity();glFrustum(-320.0, 320.0,          -240.0, 240.0,          1.0, 1000.0);// position cameraglMatrixMode(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.
Eddie RiveronSoftware EngineerCreator of 3D Wrath EngineWebsite soon!
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.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
cool, that worked, thanks! :)

now to expand on that. is 60 degrees the standard fov? and is 1 and 1/3 the standard aspect ratio?
Eddie RiveronSoftware EngineerCreator of 3D Wrath EngineWebsite soon!
The aspect ratio is (usually) the ratio between the pixel width and height of your window. If you use any other aspect ratio, you will get stretched geometry.

To make it is hell. To fail is divine.

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?
Eddie RiveronSoftware EngineerCreator of 3D Wrath EngineWebsite soon!
fov = 90 degrees
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.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!

This topic is closed to new replies.

Advertisement