Glortho Depht Sort broken

Started by white.waluigi, June 13, 2013, 17:45:57

Previous topic - Next topic

white.waluigi

i have the following code with 3 quads with different depht levels, which should take care of of which one is in front.
But the programm simply ignores the depht levl and Shows the objects in the Order their rendered.
can anyone see the my mistake?
Heres the Code:

package RND;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
 
public class Dephttest {
 
    public void start() {
        try {
	    Display.setDisplayMode(new DisplayMode(800,600));
	    Display.create();
	} catch (LWJGLException e) {
	    e.printStackTrace();
	    System.exit(0);
	}
 
	// init OpenGL
	GL11.glMatrixMode(GL11.GL_PROJECTION);
	GL11.glLoadIdentity();
	GL11.glOrtho(0, 600, 0, 400, -100, 100);
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
 
	while (!Display.isCloseRequested()) {
	    // Clear the screen and depth buffer
	    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);	
		
	    // set the color of the 
	    
	    
	    


	    
	    // This should be rendered in Front
	    GL11.glTranslatef(10f, 10f, 0);
	    GL11.glColor3f(1,0,0);
	    GL11.glBegin(GL11.GL_QUADS);
	    
	    
	    
	    GL11.glVertex3f(100,100,10);
		GL11.glVertex3f(100+200,100,10);
		GL11.glVertex3f(100+200,100+200,10);
		GL11.glVertex3f(100,100+200,10);
	    GL11.glEnd();
 
	    // This should be rendered in The middle
	    GL11.glTranslatef(10f, 10f, 0);
	    GL11.glColor3f(0,1,0);
	    GL11.glBegin(GL11.GL_QUADS);
	    GL11.glVertex3f(100,100,20);
		GL11.glVertex3f(100+200,100,20);
		GL11.glVertex3f(100+200,100+200,20);
		GL11.glVertex3f(100,100+200,20);
	    GL11.glEnd();

	    
	    // This should be rendered in the back
	    GL11.glTranslatef(10f, 10f, 0);
	    GL11.glColor3f(0,0,1);
	    GL11.glBegin(GL11.GL_QUADS);
	    GL11.glVertex3f(100,100,30);
		GL11.glVertex3f(100+200,100,30);
		GL11.glVertex3f(100+200,100+200,30);
		GL11.glVertex3f(100,100+200,30);
	    GL11.glEnd();
	    
	    GL11.glTranslatef(-30,-30, 0);

	    Display.update();
	}
 
	Display.destroy();
    }
 
    public static void main(String[] argv) {
    	Dephttest dephttest = new Dephttest();
    	dephttest.start();
    }
}

Fool Running

You have no call to GL11.glEnable(GL11.GL_DEPTH_TEST)? :P
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

white.waluigi

lol, Thanks, thats embarassing...
Have a nice weekend