   OpenGL ES orthographic depth rendering problem
  Hi, I'm coding in Java with the android opengl libraries and I have a problem. Using orthographic projection, the layering of the objects seem to be depending on the order they are drawn and not on their z-values. This would be fine if I wanted a 2d environment but I'm making a 3d environment. Here's some code://this is the initialization functionpublic void onSurfaceCreated(GL10 gl, EGLConfig config) {//Initialize Heregl.glEnable(GL10.GL_TEXTURE_2D);//Enable Texture Mapping gl.glEnable(GL10.GL_DEPTH_TEST);//Enable depth testinggl.glShadeModel(GL10.GL_SMOOTH);//Enable Smooth Shadinggl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);//Enable the vertex and texture stategl.glEnableClientState(GL10.GL_VERTEX_ARRAY);gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);gl.glMatrixMode(GL10.GL_PROJECTION);gl.glLoadIdentity();//set the projection gl.glOrthof(-screenWidth/70, screenWidth/70, -screenHeight/70, screenHeight/70, 0, -200);//set the viewportgl.glViewport(0, 0, screenWidth, screenHeight);gl.glMatrixMode(GL10.GL_MODELVIEW); //Select The Modelview Matrixgl.glLoadIdentity(); //Reset The Modelview Matrix}//The drawing functionpublic void onDrawFrame(GL10 gl) {//define color of clipping wallgl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);//clear the buffer to display the clear color gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);gl.glClearDepthf(1.0f);//select model matrixgl.glMatrixMode(GL10.GL_MODELVIEW);//reset model view matrixgl.glLoadIdentity();//I draw here using glDrawElements calls}I think I'm missing an initialization call or something, but I can't figure out what. Any help would be greatly appreciated.   
  Based on what I see here it doesn't look like you're missing anything. As long as you have depth test enabled it should work (unless you're doing something else that you aren't showing).I'd say either post more of your code, or maybe an image to show your issue?Edit: also anytime you're experiencing something weird always check for opengl errors at least at the end of each frame.   ;  AFAIK The code I omitted has to do with loading textures and transformations only.Here's a screenshot:The panels are arranged in a circle on the x-z plane and the camera is slightly elevated looking down on the panels.If you look at the left-hand side, the "Titanic" panel is obscured by the "Star Wars" panel which is supposed to be behind it. I drew the star wars panel first, and the rest in counter-clockwise order, ending with the WildWildWest panel partially seen behind the starwars panel. The renderer is giving  higher priority to the earlier object drawn(Which is the reverse of what I would expect if depth testing wasn't enabled).If I change a single line of code, the glOrthof call to a gluPerspective call instead, the panels display properly.;  I'm almost wondering if you've got your scene flipped. From what I can tell in the image it's not that the depth test isn't working, but it looks like items in the back are always overtop of items in the front.Quote:gl.glOrthof(-screenWidth/70, screenWidth/70, -screenHeight/70, screenHeight/70, 0, -200);I think you want the near/far value to be something like 0, +200. If you read the glOrtho doc it says that "if the near/far value is negative the plane is to be behind the viewer" and "-farval is the location of the negative clipping plane".Flip your farval to +200 and shift everything to the range from 0 (camera) to -200(far plane), and I think that should work.   ;  Holy smokes, good catch man. That -200 was supposed to be positive. I must have been confused thinking "negative z is into the screen..." I changed that and it displayed everything properly. Thanks a lot!   