Z Buffer

Is there any way to know the values in Z Buffer? Or is there any way to know which is the front most plane if there are several planes? OpenGL will check the values in Z Buffer and hide all the overlap parts if these parts are behide the front most(closest to the viewer) object. Is there any way for the user to know that? Thank you!

see the red book
readpixels with GL_DEPTH_COMPONENT

Thank you, Zed! My question actually is: is there any way for the programmer to know which plane is in front of another one if there are two planes in the view? OpenGL knows that with Z Buffer, however, how can I know this?

Our project: we need to retrieve some information from planes in the view. We only try to get information from the front most plane. So we need to know which plane is the front most one. Is there any way to do that?

Yes, you can find that on google.

I can tell you what not to do:-

  • Don’t rely on opengl to find out this SIMPLE information.

  • Don’t rely on opengl programmers to do your work for you, unless you’ve tried your best already.

  • Don’t post multiple posts on the SAME TOPIC - my 56k modem hates you for it.

  • Don’t post any more questions here until you’ve read some books/docs.

  • Finally, don’t take my reply too personally, please - I too have asked some stupid questions on this forum, in the past.

knackered:

If you do not really understand the question, you would better do not say a word. Real specialists never be so impatient. Actually I contacted some friends who have been OpenGL programers for years and they offered no good solutions for my question. If you are a real specialist and you understand my question and you give me a satisfied answer, I will shut up next time. Otherwise…

I worry about my English. Perhaps I do not explain my question clearly. If there are two planes in the same view and they could overlap with each other, can you tell which one is in the front? Do not tell me to use glEnable(GL_DEPTH_TEST).

Hope I am going to shut up next time.

Originally posted by knackered:
[b]I can tell you what not to do:-

  • Don’t rely on opengl to find out this SIMPLE information.
  • Don’t rely on opengl programmers to do your work for you, unless you’ve tried your best already.
  • Don’t post multiple posts on the SAME TOPIC - my 56k modem hates you for it.
  • Don’t post any more questions here until you’ve read some books/docs.
  • Finally, don’t take my reply too personally, please - I too have asked some stupid questions on this forum, in the past.[/b]

Ok, ok mr. yao. You’ve decided to take what I said personally - which leads me to think you’re maybe a young, enthusiastic, slightly arrogant fella - I like that. It will get you far…but not far enough if you don’t want to do your homework.
Your ‘specialist’ friends either don’t consider you a friend, and have therefore fobbed you off with feigned ignorance, or they are just as ignorant as yourself.

Think about it. You have 2 planes. You obviously know how to project the planes into world space, yes? You need both your planes in world space, the same as your viewpoint. Now, you know how to perform a plane-to-plane intersection test, yes?
Then why are you asking the question?
I could understand it if your 2 objects were not planes (maybe a 2 rabbit models), but they’re planes for gods sake!
I’m not a specialist - to me a specialist is the nickname of a cockney gang member, maybe someone good with safe cracking, or security systems.

Specialist answer:
Know your viewpoint origin
Know your view normal
Know your geometry
Split your geometry into non intersecting (wrt depth) parts. Choose a representative vertex on each object in question.
Calculate ((transformed vertex - origin) dot normal) for geometry in question
Choose the minimum value. This leads to the vertex closest to the eye plane and in turn to the object closest to the eye plane.

As you can see, this has absolutely nothing to do with OpenGL. You could argue that it’s related to computer graphics in general but it’s simply linear math.

[This message has been edited by zeckensack (edited 03-06-2002).]

I really think knackered was trying to tell you in a nice way.

Try searching the net and read books first.
Then search the forums for a similar question, chances are that your question is already answered many times.

In this case, you can find information on how to determine which plane is in front of the other on nehe.gamedev.net

HTH

(This problem can be solved with OpenGL and Glut)

Wow, asking the same question on both boards and then repeating the question on both boards two hours later is … is …

My suggestion would be to take a darn math class that covers 3-space (3D) mathematics. Many years of experience using opengl doesnt mean a thing if you dont know any 3d math. Now me, im taking an advanced calculus class that covers 3-space math and it has helped me a TON in graphics programming. Each day i understand some graphics concept better and/or am able to learn a new 3d technique that i wasnt able to do before. It all comes down to the math.

-SirKnight

You did make me think for a while. Actually we have up to 30 planes. These planes could be parallel with some others or intersect with others. And we know the 3D coordinates of vertex of these planes. Theoretically, you can find which plane is the most front one via the algorithm you offered if you are good at mathematics. You need to do the computation work many times because we need to compare planes pair by pair. I do not know exactly how OpenGL does this, but I guess OpenGL uses the similar algorithm and stores the information in Z Buffer. Then when OpenGL draws something, which one to draw and which one to hide is already known by referring to Z Buffer. However, is there any easy way to get the information that OpenGL already stored? Although we can do the computation to get the information I need, if the users rotate the image, we have to do all the computations again. If there is any handy way to get depth information directly, then we do not need to so much work. Besides, I am not good at mathematics(maybe you are), and I need to review my college text book to do the computation and that takes time. Any suggestion?

I think it would be better if you explained why you need this information and how you plan to use it, may be easier to give you a good suggestion that way.
If it’s for depth sorting I suggest you take a look at BSP trees.

I need to review my college text book to do the computation and that takes time. Any suggestion?

And it takes time for me to answer this stuff. Let me put it clearly:
This is basic linear math. We’re not talking rocket science here. You’ll get nowhere in computer graphics without it.
So, take your time and review your text book. It will pay off greatly.

If you want to get the info back from OpenGL, I suggest the following horridly performaning, cheap ass solution (if you don’t want to do the proper math …)

Assign a unique ‘key color’ to each object.
Disable dithering, lights, textures, blending, smooth shading and whatnot. But be sure to leave depth writes and depth testing enabled.
Render your scene to the backbuffer with the key colors assigned to the objects you want to be able to recognize.
DONT SWAP THE BUFFERS!
Read the back buffer colors and the depth buffer back with glReadPixels.
Find minimum depth value.
Find associated color value.
Find object associated with this color.

Optional:
Turn fancy rendering state for audience consumption ™ back on.
Render scene again.
Swap buffers.

Thank you all for joining the discussion and give me your reply. No matter what you guys said to me, I appreciate your concern on the topic. My English is not so good, so I might mislead you and I apologize for that. I want you guys note this point:

I post this question not to discuss Geometry, but an application of Geometry. Theoretically it is not so hard to find an answer from point of view of Geometry. I am not doing my homework. I am doing a geophysical project.

I am now descript my project and I hope this can help you understand my problem. In a typical geophysical survey, we survey a rectangle area and try to find something under the surface of this area. If we consider the depth, we get a cube. we cut the cube by slice from different directions to see what are there. Each slice is a plane. If there is something in a slice, that part of the slice looks different from the enviroment. We need to know the position of that part. We want our users to see the 3D position of the part he/she concerns when he/she points the mouse at that part. If there is only one slice(plane), we can know this by 2D-3D coordinate transformation. However, if there are more slices(planes) and they overloped with each other, if the user point to the overlapped part, we cannot get the position information since we do not know which slice(plane) the mouse point is located at. In this case, we assume that the mouse point is located at the front most slice(plane) and we want to show the position of the point on that slice(plane). Therefore, we need to know which slice(plane) is the front most one. In my impression, Z Buffer stores depth information, but I do not know if there is any function can help me to get the information, that is why I post this topic.
If my poor English still do not let you understand my problem, please let me know and I can further explain the topic. Please do not ignore the topic, thank you!

The reason I post this on two places is that I want more experts to see this question and give me an answer. The reason I post this twice is that I want to explain my question more clearly. I believe I did not say the question clearly the first time. OK, any suggestion?

We understand EXACTLY what you want to do. Read the posts above, or read the posts on the other forum. They all say the same thing. I fear it’s you who does not understand what we are saying. In that case, it is up to YOU to read up on the subject before continuing. We cannot help you unless you do.

[This message has been edited by Rob The Bloke (edited 03-06-2002).]

can’t believe i read all this. but i think the answer given to you just before you’re final message sounds to me like what you wan’t to know. the z buffer doesn’t save geometry info just pixel depth i think. so you will need to assign a color to it so you can retrieve that color with your mouse point and click function. i hope i spoke simply enough that you understand. i really tried to keep my english simple as possible.

I am thinking of writing a book on picking! If all the people that need help on that would buy it, I would be rich!!

I do not understand why people are so afraid of stencil buffers. It’s an excellent way to store “invisible” information about rendered geometry.

I made a post that hopefully solves the problem gracefully: http://www.opengl.org/discussion_boards/ubb/Forum2/HTML/007650.html

I hope it is correct (haven’t tried it).