Showing depth complexity using stencil buffer

Showing depth complexity using stencil buffer

Post by Tim Wooda » Sat, 17 Jan 1998 04:00:00



I'm working on a program and want to display the depth complexity for
each frame I render. I'm trying to use the approach outlined in the
Advanced OpenGL Siggraph notes on "Finding Depth Complexity with the
Stencil Buffer." Problem is, I don't have too much experience with
pixel operations, so there are a few areas that are unclear to me.

Here's the method that the article describes:

1) Clear the stencil and depth buffers

2) Enable stenciling

3) Set the stencil function w/glStencilFunc( GL_ALWAYS, 0, 0 ) and the

   stencil op w/glStencilOp( GL_KEEP, GL_INCR, GL_INCR )

4) Draw the scene

5) Use glReadPixels( ) w/GL_STENCIL_INDEX as format

6) Draw the stencil buffer using glDrawPixels with GL_COLOR_INDEX as
   format

7) Control over color mapping can be done by enabling color mapping
   and setting up pixel maps.

I'm using a double buffer and have set the read and write buffers to
the back buffer and I'm making sure to flush the buffer after the
write before the swap, but the screen is always white.

It's 5-7 that are giving me the trouble. What type should I take from
glReadPixles? GL_FLOAT? GL_UNSIGNED_INT?

I'm not sure how to use the mapping because I don't know what the
range should be with what glReadPixels returns. Is that dependant on
if the type is GL_FLOAT or GL_WHATEVER?

 
 
 

Showing depth complexity using stencil buffer

Post by David Blyt » Sun, 18 Jan 1998 04:00:00



>I'm working on a program and want to display the depth complexity for
>each frame I render. I'm trying to use the approach outlined in the
>Advanced OpenGL Siggraph notes on "Finding Depth Complexity with the
>Stencil Buffer." Problem is, I don't have too much experience with
>pixel operations, so there are a few areas that are unclear to me.

>Here's the method that the article describes:

>1) Clear the stencil and depth buffers

>2) Enable stenciling

>3) Set the stencil function w/glStencilFunc( GL_ALWAYS, 0, 0 ) and the

>   stencil op w/glStencilOp( GL_KEEP, GL_INCR, GL_INCR )

>4) Draw the scene

>5) Use glReadPixels( ) w/GL_STENCIL_INDEX as format

>6) Draw the stencil buffer using glDrawPixels with GL_COLOR_INDEX as
>   format

>7) Control over color mapping can be done by enabling color mapping
>   and setting up pixel maps.

>I'm using a double buffer and have set the read and write buffers to
>the back buffer and I'm making sure to flush the buffer after the
>write before the swap, but the screen is always white.

>It's 5-7 that are giving me the trouble. What type should I take from
>glReadPixles? GL_FLOAT? GL_UNSIGNED_INT?

>I'm not sure how to use the mapping because I don't know what the
>range should be with what glReadPixels returns. Is that dependant on
>if the type is GL_FLOAT or GL_WHATEVER?

The basic idea is that the stencil buffer counts the number of times
a given pixel is visited.  You would likely read the stencil buffer
back using glReadPixels with a format of STENCIL_INDEX and a type of
UNSIGNED_BYTE.  You are now left with an image where each byte holds
the depth complexity for the corresponding pixel.  You draw this
back to the screen converting these integer values back to RGBA
(assuming you were doing RGBA rendering) by using glDrawPixels with
a format of GL_COLOR_INDEX, type of UNSIGNED_BYTE and OpenGL will lookup
these index values using the color lookup tables described in the
glPixelMap manual pages.  You need to load these lookup tables
with the depth complexity -> RGBA mapping that you want to see.

If you don't load a specific PixelMap you will get the default
pixelmap which maps everything to zero.
        -db

 
 
 

1. Problem with stencil buffer and depth buffer

I'm having a strange problem with my OpenGL program which uses the stencil
buffer.  The program is written with Performer, but I will describe exactly
what performer does so it shouldn't be an issue.

Basically, I have a model of the earth and I want to select a portion of
that model (a curved section delimited by a specific latitude and longitude
set on each side) by placing a value of "1" in the stencil buffer where that
section lies.  So first I draw the earth model.  Then I draw a pyrimidical
wedge whose apex lies at the center of the earth and whose 4 edges pass through
the boundaries I want to clip at to a point about twice the radius of the
earth, where the base of the pyramid is located.  (It's like an arrow or
crossbow bolt sticking out of the surface of the earth.)  This pyramid is
drawn twice, with the first pass rendering the front-facing faces while
incrementing the stencil buffer, and the second pass renders the back-facing
faces while decrementing the stencil buffer.  If I save the stencil buffer
at each stage of the rendering I notice that the stencil buffer is not
clipped at the surface of the earth at the end of the first pass of
rendering the pyramid (the complete front-facing faces are
seen), but if I also enable the color buffer to be written I see that it is
being clipped at the earth's surface.  In other words, you can't see the
portion of the pyramid inside of the earth in the color buffer, but you
can see it in the stencil buffer.  What could allow the stencil buffer to
ignore the depth buffer test while still allowing the color buffer to use the
depth test?  How can I make the stencil buffer respect the depth buffer test?
Any hints would be greatly appreciated.

--
Eric Sokolowsky                          Scientific Visualization Studio
Scientific Visualization Programmer      NASA Goddard Space Flight Center
301.286.3751                             Code 935.0  Bldg 28  Rm S121

2. Gif animate

3. Depth buffer as a stencil buffer?

4. Info on glaux library

5. question about depth buffers and stencil buffers

6. US :: BOSTON :: MA :: 3D/2D Designer & Flash/Shockwave Expert

7. Stencil buffer only in 32 bit color depth?

8. HELP!:PS5.5 prefs?

9. stencil buffer and color depth

10. Q: Stencil Buffer Depth

11. Q: Interaction of stencil and depth buffers

12. Strange depth-stencil buffer problem...

13. problem using stencil buffer for shadow volume