I started with the Simple JGL Project, copied it and renamed it Lesson1. Then I went into source and refactored the main class, whatever it was, to call it Lesson1. Also set this new project as Lesson1.java. I then modified Brian Paul's code to make it as similar as possible to Lesson 1 - ignoring the full-screen bit, which others seem to have also done:
import com.sun.opengl.util.Animator;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;
/**
* Lesson1.java
* author: Walter Milner
* from Brian Paul (converted to Java by Ron Cemer and Sven Goethel)
*
* NeHe Lesson 1
*/
public class Lesson1 implements GLEventListener {
public static void main(String[] args) {
Frame frame = new Frame("NeHe Lesson 1");
GLCanvas canvas = new GLCanvas();
canvas.addGLEventListener(new Lesson1());
frame.add(canvas);
frame.setSize(640, 480);
final Animator animator = new Animator(canvas);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
// Run this on another thread than the AWT event queue to
// make sure the call to Animator.stop() completes before
// exiting
new Thread(new Runnable() {
public void run() {
animator.stop();
System.exit(0);
}
}).start();
}
});
// Center frame
frame.setLocationRelativeTo(null);
frame.setVisible(true);
animator.start();
}
public void init(GLAutoDrawable drawable) {
// like int InitGL(GLvoid)
// but does not return an error code?
// part of the GLEventListener interface
GL gl = drawable.getGL();
// Setup the drawing area and shading mode
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glClearDepth(1.0f); // depth buffer
gl.glEnable(GL.GL_DEPTH_TEST); // Enables Depth Testing
gl.glDepthFunc(GL.GL_LEQUAL); // type of depth test
gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int
height)
{
// like GLvoid ReSizeGLScene(GLsizei width, GLsizei height)
// reshape is part of the GLEventListener interface, and is called during
first re-paint after a resize
GL gl = drawable.getGL();
GLU glu = new GLU();
if (height <= 0) { // avoid a divide by zero error!
height = 1;
}
final float h = (float) width / (float) height;
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0f, h, 0.1f, 100.0f);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
}
public void display(GLAutoDrawable drawable) {
// like int DrawGLScene(GLvoid)
GL gl = drawable.getGL();
// Clear the drawing area
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
// Reset the current matrix to the "identity"
gl.glLoadIdentity();
}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged,
boolean deviceChanged) {
}
}
This just gives you a mysterious frame with a black background. But hey, we've started.