Frustrated Frustum

I am going through the OpenGL guide on the OpenGL homesite and I am having issues with projection perspectives. I am able to use glOrtho() and get things to look like they should. However, I am now trying to add perspective to my view. So I’ve replaced glOrtho() with glFrustum and I’m not getting what I think I should get.

I use:

gl.glFrustum(-(double)getWidth()/2, (double)getWidth()/2, -(double)getHeight()/2, (double)getHeight()/2, 2000.0, 20.0);

and I get almost what I want, but it behaves incorrectly. I am working in fullscreen mode and the view is centering the origin correctly. However, the perspective is reversed with objects getting larger the further back they are instead getting larger the closer they are. I suspect it has to do with my near value being large and my far value being small, which is the opposite of how I think it should be. If I reverse them, though, I get a really wierd result where my objects stretch immensely like looking at them through a fun house mirror.

I guess my question is, how does glFrustrum work? Am I missing a key component? I do enable GL_DEPTH_TEST and I clear the depth buffer at the start of every display call.

Having your “near” near-er than the “far” plane is the right way around. The “fun house” warping is probably because you’ve got your field of view too wide. It’s been a while since I used perspective projections, you might find that gluPerspective provides a more intuitive way to set up your projection matrix (which I believe will use your provided fov to calculate the correct left/right/top/bottom values. Using pixel values for left/right/top/bottom is probably not going to be suitable.

gluPerspective() was definitely easier to figure out. Although, I would still like to figure out my problem with glFrustrum().

All of the examples in the programming guide don’t include any ‘field of view’ methods that I can see. They do use very small numbers in there glFrustum() calls, like ‘1’ and ‘-1’. I figured that worked, because they were also drawing small objects, like glutWireCube(1.0). So, if I’m drawing bigger objects in full screen mode, it seemed like I should set the near window to be the size of the screen in pixels.