Bleh, I had the depth test in, but commented it out because it was causing problems in other areas. Put it back in, everythings fine and dandy. Oh well.
Many thanks.
Main Topics
Browse All TopicsI've just started learning opengl (via java & jogl) and am having various difficulties with it.
The biggest one however, is that I have 2 cubes floating in space, which rotate around. When cube A is in front, it all works fine, but when cube b is in front, cube is still drawn on top.
Ive uploaded an example to http://www.actionjesus.pwp
What could be causing this, and how do I fix it?
Thanks in advance
Code below (not all of it, but what I hope is revelant)
**************************
public void init(GLDrawable drawable)
{
GL gl = drawable.getGL();
this.gldrawable = drawable;
gl.glClearColor(0, 0, 0, 0);
gl.glMatrixMode(GL.GL_PROJ
gl.glLoadIdentity();
gl.glOrtho(0, 1, 0, 1, -1, 1);
gl.glEnable(GL.GL_NORMALIZ
drawable.addMouseListener(
drawable.addMouseMotionLis
}
public void reshape(GLDrawable glDrawable, int i, int i1, int i2, int i3) {
GL myGL=glDrawable.getGL();
int width=canvas.getWidth();
int height=canvas.getHeight();
myGL.glMatrixMode(GL.GL_PR
myGL.glLoadIdentity();
}
public void display(GLDrawable drawable)
{
GL gl = drawable.getGL();
GLU glu = drawable.getGLU();
gl.glClear(gl.GL_COLOR_BUF
gl.glFrustum(-1.0f, 1.0f, -1, 1, 0.8f, 10.0f);
gl.glMatrixMode(GL.GL_MODE
gl.glLoadIdentity();
gl.glEnable(gl.GL_CULL_FAC
gl.glTranslatef(-0.5f, 0.0f, -3.0f);
gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f);
gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
gl.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);
drawcube(gl);
gl.glTranslatef(1.0f, 0.0f, -1.0f);
drawcube(gl);
gl.glFlush();
}
public void drawcube(GL gl)
{
gl.glBegin(gl.GL_QUADS);
gl.glColor3f(0.0f,1.0f,0.0
gl.glVertex3f( 0.5f, 0.5f,-0.5f);
gl.glVertex3f(-0.5f, 0.5f,-0.5f);
etc....
}
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: WolfgangStPosted on 2006-02-21 at 18:56:56ID: 16015247
Seems like you simply forgot to enable the depth test.
For enabling depth buffer test use
glEnable(GL_DEPTH_TEST)
Also make sure that your current device you are rendering on supports depth buffer, if it still does not work after enabling the check. This is somewhere in your init code where you should have a possibbility to specify the depth bits (precision) to be used.