I’m learning OpenGL principles from Edward Angel’s book, “OpenGL: A Primer”, translating from C into Java/jogl as I go. His first example for working with the camera looks like:
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glutWireCube(0.5);
glutSwapBuffers();
}
Here’s my translation:
public void display(GLDrawable drawable) {
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
glu.gluLookAt(1.0, 1.0, 1.0, //eye
0.0, 0.0, 0.0, //object
0.0, 1.0, 0.0); //up
glut.glutWireCube(gl, 0.5f);
gl.glFlush();
}
In fact, I’m getting a black screen. No image. Although I can get images in other 3D examples, where I’m not using gluLookAt. Where could I be going wrong? BTW, is there a jogl equivalent for glutSwapBuffers()? It certainly doesn’t seem to be in the GLUT interface.
My init code is below, in case that’s the issue:
public void init(GLDrawable drawable) {
this.gl = drawable.getGL();
this.glDrawable = drawable;
drawable.setGL( new DebugGL(drawable.getGL() ));
glu = drawable.getGLU();
drawable.addMouseListener(this);
drawable.addMouseMotionListener(this);
float pos[] = { 20.0f, 5.0f, 10.0f, 0.0f };
gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, pos);
gl.glEnable(GL.GL_CULL_FACE);
gl.glEnable(GL.GL_LIGHTING);
gl.glEnable(GL.GL_LIGHT0);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glColor3d(1.0, 1.0, 1.0);
}