views:

117

answers:

1

I've been working with the depth buffer in OpenGL (JOGL) to ensure certain items are rendered in front of others by disabling the depth buffer (detailed in my previous question http://stackoverflow.com/questions/2516086/java-opengl-saving-depth-buffer).

This works, except when I set the color of an item that is being drawn when the depth test is disabled, none of the material shininess shows up. The item is rendered as a darker version of the original color (it seems like there is no lighting effect really applied to it). Is there a reason why this would be happening? and how might I prevent this?

thanks, Jeff

+2  A: 

Since you got no answers so far, I'll try to give it my shot, although I'm really a bit guessing here.

A few reasons I can imagine, why the effect you see would happen:

  • In contrast to the ambient and diffuse component of the lighting model, the specular component needs to take into account the eye location relative to the object and light source. So this will probably be faster, when OpenGL uses the depth buffer. I assume, that this way - for every pixel to be drawn - it could use the depth value to complete the eye coordinates with the z component.

  • Maybe it's also related to light attenuation? When light attenuation is used, OpenGL calculates the distance, which the light has to travel before reaching your eye (or does it simplify by only calculating the distance between the light and the object? I'm not sure.)

So I assume, that it's not possible to use lighting correctly without a depth buffer. I think you mentioned in your other post, that you can't just clear the depth buffer, because it would interfere with the rest of the application? I think there should be a solution with stencils, something similar to "Example 10-1 : Using the Stencil Test" in http://www.glprogramming.com/red/chapter10.html (it's written in C, but I hope it's similar in JOGL). The stencil would simply bar the remaining application from drawing over your precious pixels.

Chris Lercher
Thanks, Chris. I think you're right. I was able to work around the problem by actually disabling the depth mask on all the non-selected items and render them last. This ensures they end up on top. Though I think using the stencil is a better solution. Thanks.
Jeff Storey