getting Z buffer without rendering

Hi,

I would like to know how to get the Z buffer of a scene without rendering it onto the screen?
Cheers,

c.

disabling color buffer writing is one way.
What do you want to do with that ?

SeskaPeel.

Basically I want to get the zbuffer to get the binary silhouette of the scene: 0 if background, 1 if foreground.
I am not at all interested in drawing it as I will change every iteration the parameters of the scene.

c.

basically you just need stencil testing no ?

If stencil is this binary silhouette, yes.

c.

Basically, I am looking for an example code where one wants to render a sphere e.g. and gets the binary silhouette without rendering it. I work under linux.
Cheers,

c.

First off, you need to have a stencil buffer allocated. Then you set the stencil test glStencilFunc( GL_ALWAYS, 1, ~0 )), then set the stencil operation glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE ) and then enable testing (glEnable( GL_STENCIL_TEST )).

You then need to remember to clear the stencil bits in the frame buffer when initializing the frame for rendering.

Now each frame for each fragment that passes the z-test the stencil value of the corresponding pixel is set to 1, others are left untouched.

You now have a stencil mask in the frame buffer that you can use for further stencil testing.

  • PD

Telling us what you intend to do with that could help.

SeskaPeel.

Thanks all, I finally solve my problem with MesaGL which has some functions to perform off-screen rendering.

c.