Hi - after following this tutorial: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=05
(more or less), the rear of my cube consitently gets drawn in front of the front of my cube (or maybe the front is somehow transparent). Any advice would be greatly appreciated. Here is the code I am using:
import java.awt.;
import java.awt.event.;
import net.java.games.jogl.*;
class JOGLTest extends Frame implements GLEventListener {
public JOGLTest () {
super.setUndecorated(true); //Undecorated for Fullscreen mode
super.setIgnoreRepaint(true); //Ignore Repaint for Fullscreen mode
super.addWindowListener(new WindowAdapter() { //Exit on window close
public void windowClosing (WindowEvent we) {
System.exit(0);
}
});
GLCapabilities capabilities = new GLCapabilities(); //Get GLCapabilities for GLCanvas
GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(capabilities); //Create GLCanvas
canvas.addGLEventListener(this); //Listen for GL Events
super.add(canvas); //Add canvas to frame
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(this); //Set Fullscreen mode
}
public static void main (String args[]) {
new JOGLTest();
}
public void init (GLDrawable gld) {
GL gl = gld.getGL();
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
gl.glClearDepth(8.0f);
gl.glEnable(GL.GL_DEPTH_TEST);
}
public void reshape (GLDrawable gld, int x, int y, int width, int height) {
GL gl = gld.getGL();
GLU glu = gld.getGLU();
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0,(double)width/height, 0.0, 10.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
}
public void display (GLDrawable gld) {
GL gl = gld.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, -5.0f);
//gl.glRotatef(45.0f, 0.0f, 1.0f, 0.0f); //Reenable when cube is drawn correctly
gl.glBegin(GL.GL_QUADS);
gl.glColor3f(1.0f, 1.0f, 1.0f);
gl.glVertex3f(1.0f, 1.0f, -1.0f);
gl.glVertex3f(-1.0f, 1.0f, -1.0f);
gl.glVertex3f(-1.0f, 1.0f, 1.0f);
gl.glVertex3f(1.0f, 1.0f, 1.0f);
gl.glColor3f(0.0f, 0.0f, 0.0f);
gl.glVertex3f(1.0f, -1.0f, 1.0f);
gl.glVertex3f(-1.0f, -1.0f, 1.0f);
gl.glVertex3f(-1.0f, -1.0f, -1.0f);
gl.glVertex3f(1.0f, -1.0f, -1.0f);
gl.glColor3f(0.0f, 0.0f, 1.0f);
gl.glVertex3f(1.0f, 1.0f, 1.0f);
gl.glVertex3f(-1.0f, 1.0f, 1.0f);
gl.glVertex3f(-1.0f, -1.0f, 1.0f);
gl.glVertex3f(1.0f, -1.0f, 1.0f);
gl.glColor3f(1.0f, 0.0f, 0.0f);
gl.glVertex3f(1.0f, -1.0f, -1.0f);
gl.glVertex3f(-1.0f, -1.0f, -1.0f);
gl.glVertex3f(-1.0f, 1.0f, -1.0f);
gl.glVertex3f(1.0f, 1.0f, -1.0f);
gl.glColor3f(0.0f, 1.0f, 0.0f);
gl.glVertex3f(-1.0f, 1.0f, 1.0f);
gl.glVertex3f(-1.0f, 1.0f, -1.0f);
gl.glVertex3f(-1.0f, -1.0f, -1.0f);
gl.glVertex3f(-1.0f, -1.0f, 1.0f);
gl.glColor3f(0.5f, 0.5f, 0.5f);
gl.glVertex3f(1.0f, 1.0f, -1.0f);
gl.glVertex3f(1.0f, 1.0f, 1.0f);
gl.glVertex3f(1.0f, -1.0f, 1.0f);
gl.glVertex3f(1.0f, -1.0f, -1.0f);
gl.glEnd();
}
public void displayChanged (GLDrawable gld, boolean modeChanged, boolean deviceChanged) {
}
}