 |
|
| Computers Forum Index » Computer - Graphics - API (Opengl) » Stencil buffer problem... |
|
Page 1 of 1 |
|
| Author |
Message |
| Chris Theis... |
Posted: Thu Sep 03, 2009 3:43 pm |
|
|
|
Guest
|
Hi all,
I'm currently facing some problems with the stencil buffer which I
don't quite understand. Probably it's a pretty simple & stupid mistake
and I'd appreciate if somebody could help me to spot my error.
What I would like to achieve is the following for a very simplified
scenario: I'm drawing for example 2 rectangles that are directly
adjacent to each other and they share one edge. I'm drawing the filled
polygons as well as the edges for each polygon and this is what I get:
+--------+--------+
| | |
| | |
+--------+--------+
However, I'd like to remove this shared edge in the drawing process so
that I end up with the outline of both polygons only. As both polygons
are seperate objects they actually don't know that they are adjacent
from a geometrical point of view. That's why I'm trying to remove the
shared edge at the rendering step using the stencil buffer.
At first I disable the color buffer and draw the edges of each polygon
into the stencil buffer. If a line is drawn only once the bits in the
stencil buffer should be set. However, if the line is drawn twice
because the edge is shared by two polygons the corresponding bits
should be cleared in the stencil buffer. In a second step the color
buffer is enabled and only those edges should be drawn which have a
corresponding bit set in the stencil buffer.
The code with which I'm trying to achieve this is the following but
currently it fails for a reason which I can't spot right away. Any
help on this would be greatly appreciated!
// set up stencil buffer
glEnable( GL_STENCIL_TEST );
glClearStencil( 0x0 );
glClear( GL_STENCIL_BUFFER_BIT );
glEnable( GL_DEPTH_TEST );
glDepthFunc( GL_LESS );
// disable the color buffer
glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
glStencilFunc( GL_ALWAYS, 0x0, ~0);
// set 1 to every pixel where the depth test passes = nothing has
been drawn yet
// clear the bit if the depth test fails = something has been drawn
already
glStencilOp( GL_CLEAR, GL_CLEAR, GL_INCR);
RenderContoursOnly();
glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
// render only those remaining contours which have been drawn only
once
glStencilFunc( GL_EQUAL, 0x1, ~0);
glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP);
RenderContoursOnly();
glDisable( GL_STENCIL_TEST );
Thanks a lot
Chris |
|
|
| Back to top |
|
|
|
| fungus... |
Posted: Thu Sep 03, 2009 10:38 pm |
|
|
|
Guest
|
On Sep 3, 5:43 pm, Chris Theis <chris.th... at (no spam) gmail.com> wrote:
Quote:
The code with which I'm trying to achieve this is the following but
currently it fails for a reason which I can't spot right away. Any
help on this would be greatly appreciated!
glStencilOp( GL_CLEAR, GL_CLEAR, GL_INCR);
Is "GL_CLEAR" a valid stencil operation...?
--
<\___/>
/ O O \
\_____/ FTB.
http://www.topaz3d.com/ - New 3D editor for real time simulation |
|
|
| Back to top |
|
|
|
| Chris Theis... |
Posted: Fri Sep 04, 2009 7:56 am |
|
|
|
Guest
|
Quote: glStencilOp( GL_CLEAR, GL_CLEAR, GL_INCR);
Is "GL_CLEAR" a valid stencil operation...?
Sorry, that was meant to be GL_ZERO. But it doesn't really change
anything.
Cheers
Chris |
|
|
| Back to top |
|
|
|
|
|
All times are GMT
The time now is Tue Dec 01, 2009 6:35 pm
|
|