PDA

View Full Version : overlapped space



krol
06-03-2002, 11:55 PM
Hello everyone

I have two overlapped planes and I want to draw only a place where these planes overlapping. Is it possible and if so, is there any source code example of that.

Best regards

Marcin

ScottManDeath
06-04-2002, 02:46 AM
Hi

you could do this using the stencil buffer.

At first you render your first polygon and set the stencil operation so that it increases where depth test passes. So you have you polygon in the stencil buffer. Dont forgrt to disable color buffer writing using glColorMask(..) Then you render your second polygon also incrementing the stencil buffer.
Now you enable color buffer writning and set the stencil buffer function so that stencil test passes when stencil equal to 2; and thats it. Then you render a quad all over the screen and you have the intersection

Bye
ScottManDeath

Devulon
06-04-2002, 04:28 AM
Ummm Do you really need 3 passes. Can't you just render the first object into the stencil only, doing an inc is fine. And then render the second one (with Color Writes enabled) with a stencil == 1 test.

Thats only 2 passes and I think it should come out the same unless I am seriously missing something.

Devulon

ScottManDeath
06-04-2002, 05:36 AM
Originally posted by Devulon:

Thats only 2 passes and I think it should come out the same unless I am seriously missing something.

Devulon



Hi

thats right, I offer that I was to lazy to think about it to the last consequence http://www.opengl.org/discussion_boards/ubb/wink.gif
Indeed 2 passes are better than 3

Bye
ScottManDeath

krol
06-04-2002, 07:12 AM
[QUOTE]Originally posted by ScottManDeath:
[B] Hi

thats right, I offer that I was to lazy to think about it to the last consequence http://www.opengl.org/discussion_boards/ubb/wink.gif
Indeed 2 passes are better than 3

Hello again

I'm sorry but neither 3 nor 2 passes doesn't work correctly for me. I'm using that code:

glColorMask(0,0,0,0);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS,1, 1);
glStencilOp( GL_REPLACE, GL_REPLACE, GL_REPLACE );

glutSolidTeapot(3.0);

glColorMask(1, 1, 1, 1);
glStencilFunc(GL_EQUAL, 1, 1);
glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );

glutSolidTeapot(3.0);

In this case whole teapot surface is overlapped but there is nothing drawn. What am I doing wrong? Thanks for answers.

Marcin

j
06-04-2002, 07:21 AM
I would guess that your depth test is set to GL_LESS. Try setting it to GL_LEQUAL.

j

ScottManDeath
06-04-2002, 07:21 AM
Originally posted by krol:
glStencilFunc(GL_ALWAYS,1, 1);

Hi

this should be
glStencilFunc(GL_ALWAYS,0xffffffff,0xffffffff);
to enable using all stencil buffer bits

before your second pass you should
glDepthFunc(GL_EQUAL);
to render exactly where you already rendered

Perhaps I misunderstand what you want to reach, perhaps you can tell us more about your intention ?

Bye
ScottManDeath

krol
06-04-2002, 10:41 PM
hello again

I would like to draw model ( for example teapot ) and some plane, but only overlapped place should bie visible, so it should be thin line demostrating boundary of the model.

Thanks for answers - Marcin