View Full Version : How to modify z-values in depths buffer using OpenGL function

11-20-2002, 06:08 PM
How to modify z-values in z buffer using OpenGL function? I want to modify the values in depths buffer to change the hiding relationships, such as rendering polygons object and volume objects

11-20-2002, 06:33 PM
u can write into the depth buffer by using
glDepthFunc( GL_ALWAYS );
this will replace whatever depth values are already there with the new ones.
use glColorMask(0,0,0,0); + draw the new polygons into the scene, they wont show up but there depth values will. another method is using glDrawPixels( .. , GL_DEPTH_COMPONENT )

11-20-2002, 07:05 PM
I had written codes before as follows:
glDrawPixels(m_DibWidth,m_DibHeight,GL_DEPTH_COMPO NENT,GL_FLOAT,m_pDepths);
But,it seems to have no effects. Can you give me more detailed infomation about this codes?thanks!

11-20-2002, 10:55 PM
BTW take a look at this sample ( works on windows) http://www.delphi3d.net/download/bufferregion.zip

this sample writes to depth buffer ...
and performs its update while objects move over backgroud.

though it is on delphi but opengl calls
read quite well.....

there are quite a bit of other approaches I might think of for ex using

depth texture and shadow texture extension
(the last allows depth comparisons)

or using shaders ( the same way as directx has texm3x2depth or texdepth instructions... though there are no direct analogues in opengl but there are other means ask others ...) for ex
as far as I know upcoming GeforceFx will directly support depth amanipulation instructions in OpenGl
(NV_fragment_program extension).

11-21-2002, 01:08 AM
Originally posted by yfn:
I had written codes before as follows:

Most likely your raster position fell out of the view volume und got marked invalid.

Raster positions go through the same transformations as vertices. So you need the coordinate of a vertex that lies exactly at the bottom left corner of your screen and supply that to glRasterPos3f.

Another problem is that raster positions are 'marked invalid' when they're outside of the view volume - even a tiny bit. If you call DrawPixels with an invalid raster pos, nothing is drawn, no clipping or anything, just nothing.

That's lined out in the 'Avoiding 16 common pitfalls' document somewhere on the main site btw http://www.opengl.org/discussion_boards/ubb/wink.gif

Two ways to do better:
1)Use the ARB_window_pos extension whenever available. It lets you specify coords in window space, so it's much easier and more intuitive to use. In your example you could simply replace with glWindowPos2iARB(0,0) and it would already work.

2)Load the identity matrix to both modelview and projection. Then you can use glRasterPos2f(-0.5f,-0.5f) (or something really close to that ...) and glDrawPixels.

[This message has been edited by zeckensack (edited 11-21-2002).]

11-21-2002, 05:01 AM
Thanks zed,SergeVrt,zeckensack for heartily replying my question.

I just have solved the problem.I use this techniques to reseach on virtual endoscopy in which there are volume objects and traditional geometry polygon objects. If some of you are now or past engaged in reseach on VE, I want to discuss with these people.