View Full Version : getting Z buffer without rendering
04-07-2005, 03:31 AM
I would like to know how to get the Z buffer of a scene without rendering it onto the screen?
04-07-2005, 03:37 AM
disabling color buffer writing is one way.
What do you want to do with that ?
04-07-2005, 03:44 AM
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.
04-07-2005, 04:47 AM
basically you just need stencil testing no ?
04-07-2005, 04:58 AM
If stencil is this binary silhouette, yes.
04-07-2005, 05:18 AM
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.
04-07-2005, 07:23 AM
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.
04-08-2005, 01:50 AM
Telling us what you intend to do with that could help.
04-08-2005, 02:45 AM
Thanks all, I finally solve my problem with MesaGL which has some functions to perform off-screen rendering.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.