glfrustrum and clipping planes

Hi everyone,

I’m having problems with glFrustum and specifically its z_far clipping plane. I have searched the OF forum and other forums for a similar problem and although several have had problems with glFrustum I didn’t really have success trying any of the suggestions replied.

The situation is that I have loaded several 3D models into a scene creating a small game. However, the scene have grown pretty large at this point and now I cannot see the whole scene. Basically it is a long hall with an opponent in the other end and you have to shoot at this opponent. But not the hall have been cut/clipped so that I cannot see the other end.

I have set the following code in my OF standard testApp::windowResized:

glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -1.0, 1.0, 3.0, 5000.0);
glMatrixMode (GL_MODELVIEW);

I’m pretty sure there is a very simple explanation to my problem but I cannot seem to find it. I have as I understand it set the z_far and hereby moved the clipping plane to 5000 units. But I cannot see any change in the graphics.

I have even tried moving the code to setup, but I read somewhere that the glFrustum should be run before draw() so I moved it back to windowResized.

Does anyone know what the problem might be?


Sometimes when glFrustum doesn’t work the way I expect, I use gluPerspective and gluLookAt instead. Normally I’m just making a mistake about where my “camera” is located.

hey kylemcdonald,

I found out that I had misunderstood the part where I have to put it before draw(). Apparently I had to place the code WITHIN the draw() function. Sorry to have wasted your time :slight_smile: But thanks anyway for your reply I think I will try using gluPerspective instead as you say, because the scene doesn’t quite look as I want with glFrustum as the fov is too extreme.


No worries! I’ve been thinking about the projection matrix recently too, so it happened to be on my mind anyway.

I think it needs to be in draw() because, if you look in app/ofAppGlutWindow.h you’ll see:

if( bEnableSetupScreen )ofSetupScreen();  

ofSetupScreen() modifies the projection matrix, and is called on the first draw(). So this will override anything you’ve done in setup().

It could be kind of neat to have an ofPerspective and ofFrustum that, when used, call disableSetupScreen() and therefore let you define your projection matrix once in setup() instead of draw().