Share Depth Buffer between Ortho and Proj modes?

Started by
4 comments, last by awdorrin 14 years, 1 month ago
Is it possible to share the depth buffer between Projection and Orthographic modes? Reason I am asking is this: In my program, I draw the 3d scene using Projection mode, I then overlay text and symbols using Orthographic mode. I had hoped that if I rendered an object in projection mode, that the object could occlude the text or symbols drawn at a deeper depth, while in orthographic mode. It seems that is not the case. I can provide more details if needed, but simply put, I have a certain section of my 3d-view, that I do not want anything rendered within, even if it is rendered from the orthographic mode.
Advertisement
My guess is that you will have a hard time getting the depth buffer to do what you want. The depth buffer doesn't store the "distance" from the camera, it stores a normalized float that is based on your clip planes and the projection mode.

Your clip planes would certainly be different in projection and orthographic mode, and I believe the depth buffer is linear in orthographic mode and non-linear in projection mode, so it does not really make much sense to try to compare the same buffer in both modes.

Have you considered using a stencil buffer if you just want to mask out certain areas of your screen from being rendered over? Seems like a much easier solution to your issue.

[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
The depth buffer is not changed when you switch to a different projection matrix, so the answer is yes.

You'll have to find a way to draw your orthographic text at the depth you need. With glOrtho you can use the same near and far plane as with your projection. Then your Z coordinate should give you a measure of depth, where -Zfar is the furthest away.
EDIT: Like the poster above me stated, depth is linear in orthographic view, so the comparison will be difficult.
I am drawing my orthographic items at close to the far depth I defined for my orthographic view, the 'clipping' items, drawn in the projection mode are being drawn at a distance close to the front of the view.

For instance Orthographic depths are defined as 0 to 400 while
projection is defined as 1 to 400.

The objects being drawn in projection mode are being placed at a depth of -30, while the text and lines I am rendering are being placed at a depth of -390.

I was concerned about the non-linear depth of the projection view causing problems, so this is one reason I chose the above values.

I can look into the possibility of using a stencil buffer, but I am not familiar with them at this point (only been coding in OpenGL for a few months now, learning as I go.)

What I am trying to do is this: I have an 'occlusion zone' defined with a GLU tessellation object. I draw this object in projection mode, then switch to orthographic mode to write text labels and lines. (For instance, one line represents the horizon line, but the part of the horizon line that is behind the occlusion zone should be hidden.

When I try to draw this horizon line in projection mode, it does get hidden - but I have a hard time recalculating the ends as I change scene, which is why I switched to drawing the horizon line in ortho mode.

(Seems like its always one step forward and two steps back for me as I have been working on this project.)

Guess I'll need to review my code and make sure that my blending functions are set properly still, might be having an issue in that area.

Thanks for the confirmation that this should work :)
I think what you really want to do is render that object to texture, then draw a quad using that texture over the area where you want the object to show up in your GUI.
Well, I played around with different settings, changed my 'farZ' distance for both the Projection and Orthographic modes to 200, then drew my line at -199, and the object started getting clipped again, as I wanted.

Nnot quite sure why it did not work with the farZ set at 400 and the depth of the line at -390 (orthographic)

I have a feeling that something strange was going on, because before I made the above changes to the farZ, if I moved my occlusion zone to a depth of 1 (by moving my camera forward) the line clipped as well.

In any case, its working now, which sometimes is all you can ask. ;-)

Thanks for the assistance!

This topic is closed to new replies.

Advertisement