Here is the full code listing
Now the highlights:
import com.sun.opengl.util.*; //needed for GLUT
...
private GLU glu;
private GLUT glut;
We import the necessary library and declare class variables for glu and glut objects. In our init() method we instantiate them.
We create a method to set the camera angles. We call this method inside reshape() with a specified aspect ratio and in display() with -1. The projection and modelview matrices are set and our viewing perspective.
private void track_camera(GL gl, float ratio) {
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
if (ratio < 0) {
glu.gluPerspective(45.0f, ratio, 1.0f, 500.0f);
} else {
glu.gluPerspective(45.0f, 1.0f, 1.0f, 500.0f);
}
gl.glMatrixMode(gl.GL_MODELVIEW);
gl.glLoadIdentity();
}
We set our eyes viewing angle
glu.gluLookAt(150.0f, 150.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
Finally we draw some shapes in the method, pushing onto the matrix stack, translating the position, and then popping the view matrix from the stack.
...
//blue cone
gl.glPushMatrix();
gl.glColor3f(0.0f, 0.0f, 1.0f);
gl.glTranslatef(50.0f, 0.0f, -60.0f);
glut.glutSolidCone(25.0f, 50.0f, 50, 50);
gl.glPopMatrix();
...