PDA

View Full Version : setting the near clip with gluPerspective



GameMaker
11-28-2002, 08:32 AM
I want to change the setting of the near clip when drawing different parts of the scene so that certain parts of the scene are clipped and other parts are not clipped.

I tried this...

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (GLfloat) 640 /(GLfloat) 480, nearPlaneDist, 100.0f);
glMatrixMode(GL_MODELVIEW);

but it isn't quite working correctly. My question is: Can I just call gluPerspective anywhere in my code? Or do I have to always call gluPerspective first, before doing any transformations? I guess I might need to do something like this...

glGetFloatv(GL_MODELVIEW_MATRIX,savedMatrix);
glLoadIdentity();

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (GLfloat) 640 /(GLfloat) 480, nearPlaneDist, 100.0f);
glMatrixMode(GL_MODELVIEW);

glMultMatrixf(savedMatrix);

Is there an easier/better way to do this? Thanks in advance!

Bob
11-28-2002, 08:47 AM
You can set the projetion matrix anywhere you like.

GameMaker
11-28-2002, 01:03 PM
Will changing the near plane affect the depth values at all?

Bob
11-28-2002, 01:29 PM
If the far plane is far out compared to the near plane, changing the near plane will have a great impact on the precision of the depth buffer. You should always have the far plane as far out as you can possibly accept for best precision.

GameMaker
11-28-2002, 02:08 PM
Well, I have the near clip out at 13 and the far at 100 and render. Then I change the near to 0.1 and render again and it seems like the depths are not correct because the last and closer polys rendered are partially in back of the first. Maybe I should look into glDepthRange and partition it into two areas? Does that sound like a good way to go?

GameMaker
11-28-2002, 02:36 PM
Used glDepthRange(0.1,1.0) and glDepthRange(0.0,0.09999)...that fixed it. Thanks!