PDA

View Full Version : Changing Depth Buffer while Rendering



Sheepie
04-14-2001, 08:23 PM
I have been working on a model editor for the last 4 months and have OpenGL doing all of my rendering. I have used a 16-bit depth buffer because it runs considerably faster than a 24 or 32 bit depth buffer. I have made the zNear, zFar clipping planes equivalent to 2x the Models radius on either side of the model with zNear never going under 1.0 and zFar never getting closer than 10.0 + zNear. Here is my problem.

When rendering rather large models. Radius of over 100 units, I'm seeing the swimming effects on touching polygons. I realize why this happens and I have searched on a way to alleviate this, but most suggestions seem to hint that the only way to solve the problem would be to make zNear,zFar as close to the model is possible(done that), and that setting your Depth Buffer to a higher bit depth(would make a considerable performance hit), so I got to checking out various ways of setting the zNear,zFar clipping planes and came across this function-

void glDepthRange(GLclampd znear,GLclampd zfar)

Is this simply a quick and dirty method of changing the zNear,zFar clipping region? or something else entirely.

If someone knows if this or another way of changing the zNear,zFar clipping planes that is quick(i.e., not using a glPerspective call) and can be done while rendering, then I thought I could draw each Sub-Model(part of the model) seperately enclosing it in a zNear,zFar clipping region the size of the Sub-Model, thus increasing the Z buffer accuracy without hindering performance.

duckman
04-14-2001, 10:21 PM
this is how Ive aproached the problem in the past.

if(view==2)
{//near clipping
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-50.0F, 50.0F, -50.0F, 50.0F, 100.0F, 300.0F);
glMatrixMode(GL_MODELVIEW);
}
else
{//far clipping
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-50.0F, 50.0F, -50.0F, 50.0F, 100.0F, 600.0F);
glMatrixMode(GL_MODELVIEW);
}

however Ifve neverneeded to consider it for speed like you have..

If I was in your position I would brobably pre compute several projection matrices with diferent clipping values save them all to to local memory and simply load tem with glLoadMatrix() every time I needed to change.

Sheepie
04-15-2001, 03:00 PM
Would this change what has already been drawn or clear it out so to speak?

When I tried using the glDepthRange, I was able to get some weird effects, but nothing usable. I realize that this is probably a really odd question, but I'm really don't like the wavies, and 24/32 bit depth buffer runs sooo slow. I suppose I could do Depth sorting myself, however that would also mean depth sorting the faces as well which could be overly complicated for an editor.

NeoTuri
04-16-2001, 11:23 AM
glClipPlane()

Sheepie
04-16-2001, 07:24 PM
I thought Clip Planes were used mainly to clip some object within them. Do they improve the accuracy of the Depth Buffer?

Michael Steinberg
04-16-2001, 11:52 PM
Well, well. If you sort the objects by depth, you can draw with different depth ranges. Just remember to clear the zbuffer upon a depth range change.