Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I've been working on this problem for a while now. My problem is that the sphere in the top image, is under-lapping the plane which should have a lower Z value. Although, when depth testing is disabled, it is resolved. But it favors draw order over actual fragment depth value. I was changing the depth mask out of desperation. ;)

GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
rootObject.render(ambient);

GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);
GL11.glDepthMask(false);
GL11.glDepthFunc(GL11.GL_EQUAL);

for(int i = 0; i < lights.size(); i++){
    lights.get(i).use();
    rootObject.render(lights.get(i).getProgram());
}

GL11.glDepthFunc(GL11.GL_LESS);
GL11.glDepthMask(true);

-- Screenies:

GL11.glEnable(GL11.GL_DEPTH_TEST);

depth issue1

GL11.glDisable(GL11.GL_DEPTH_TEST);

depth issue2

share|improve this question

closed as unclear what you're asking by Krom Stern, Anko, Josh Petrie Dec 3 '14 at 16:53

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

1  
It is unclear what you asking. What is the problem exactly? –  Krom Stern Nov 24 '14 at 5:59
    
And why do you think you need to change GL11.glDepthMask ? –  Krom Stern Nov 24 '14 at 6:00
    
My problem is that the sphere in the top image, is under-lapping the plane which should have a lower Z value. Although, when depth testing is disabled, it is resolved. But it favors draw order over actual fragment depth value. I was changing the depth mask out of desperation. ;) –  Ecumene Nov 24 '14 at 6:15
    
@Ecumene Edit that into the question. –  Anko Nov 26 '14 at 12:25

2 Answers 2

From the looks of it, you need to throw glDepthMask out.

GL11.glEnable(GL11.GL_DEPTH_TEST); // Enable depth testing
GL11.glEnable(GL11.GL_BLEND); // Enable blending
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); // Common blending formula for transparency
rootObject.render(ambient); // Background

GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE); // This is uncommon blending formula ..
GL11.glDepthFunc(GL11.GL_LEQUAL); //<-- Less or Equal = LEqual

for(int i = 0; i < lights.size(); i++){
    lights.get(i).use();
    rootObject.render(lights.get(i).getProgram()); // spheres?
}
share|improve this answer
    
Still isn't working... Same result as the second image –  Ecumene Nov 24 '14 at 15:22
    
You did not say - What is the desired result? –  Krom Stern Nov 24 '14 at 15:36
    
I wanted the sphere to be overlapping the plane, with depth testing. But when depth is enabled, the plane gets drawn over the spheres –  Ecumene Nov 24 '14 at 20:34
    
Try also removing the GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE); It looks out of place too. –  Krom Stern Nov 24 '14 at 20:42
    
That's for the shader-light pass. –  Ecumene Nov 24 '14 at 21:21
up vote 0 down vote accepted

Turns out, the problem was my projection matrix. I found this error when I was switching vector math libraries. And I forgot transformations in javax's vecmath are row-major order. So I switched the near and far planes, and it worked perfectly.

(0.1f, 1000f) to (1000f, 0.1f)
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.