PDA

View Full Version : Stencil and depth buffer clearing



Ketracel White
02-02-2004, 02:06 PM
I have the following problem:


I'm drawing a scene with a stencil. After that I'm drawing a different scene into the stencil.

My problem is that the first scene contains translucent objects which have to be drawn over both the original scene and the stencil with depth buffer information of the original scene.

Is there a way to clear the depth buffer only in the current stencil area because I don't want to redraw the first scene?

ZbuffeR
02-03-2004, 08:08 AM
You seem to have 2 distinct problems here, let's deal with the easiest first:

1) clearing the depth buffer only in the current stencil area :




glStencilMask(0);
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
//glBufferMask(GL_TRUE); // activated by default

<draw a large non textured quad almost at zfar distance>
< or use glClear(GL_DEPTH_BUFFER_BIT); I am not sure>

glStencilMask(0xFFFFFFFF);
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);


2) first scene contains translucent objects which have to be drawn over both the original scene and the stencil with depth buffer information of the original scene.

mmh, I am not really sure to undersdant what you mean. A picture may help ?
And beware of substractive transparency, order does matter.


[This message has been edited by ZbuffeR (edited 02-03-2004).]

Ketracel White
02-04-2004, 05:54 AM
Originally posted by ZbuffeR:
You seem to have 2 distinct problems here, let's deal with the easiest first:

1) clearing the depth buffer only in the current stencil area :




glStencilMask(0);
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
//glBufferMask(GL_TRUE); // activated by default

<draw a large non textured quad almost at zfar distance>
< or use glClear(GL_DEPTH_BUFFER_BIT); I am not sure>

glStencilMask(0xFFFFFFFF);
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);


2) first scene contains translucent objects which have to be drawn over both the original scene and the stencil with depth buffer information of the original scene.

mmh, I am not really sure to undersdant what you mean. A picture may help ?
And beware of substractive transparency, order does matter.


[This message has been edited by ZbuffeR (edited 02-03-2004).]

It's supposed to be some kind of holographic monitor. So the translucent objects in front of this monitor must be drawn after its contents. That's all.
I don't have pictures because I didn't get it to work yet. I'll try your suggestion. I hope it helps.