/* draw a point */ /* Java's supplied classes are "imported". Here the awt (Abstract Windowing Toolkit) is imported to provide "Frame" class, which includes windowing functions */ import java.awt.*; // JOGL: OpenGL functions import net.java.games.jogl.*; /* Java class definition: "extends" means "inherits". So J1_0_Point is a subclass of Frame, and it inherits Frame's variables and methods. "implements" means GLEventListener is an interface, which only defines methods (init(), reshape(), display(), and displaychanged()) without implementation. J1_0_Point will implement GLEventListener's methods and use them. */ public class J1_0_Point extends Frame implements GLEventListener { static int HEIGHT = 400, WIDTH = 400; static GL gl; //interface to OpenGL static GLCanvas canvas; // drawable in a frame public J1_0_Point() { // constructor //1. specify a drawable: canvas GLCapabilities capabilities = new GLCapabilities(); canvas = GLDrawableFactory.getFactory().createGLCanvas(capabilities); //2. listen to the events related to canvas: reshape canvas.addGLEventListener(this); //3. add the canvas to fill the Frame container add(canvas, BorderLayout.CENTER); /* In Java, a method belongs to a class object. Here the method "add" belongs to J1_0_Point's instantiation, which is frame in "main" function. It is equivalent to use "this.add(canvas, ...)" */ //4. interface to OpenGL functions gl = canvas.getGL(); } public static void main(String[] args) { J1_0_Point frame = new J1_0_Point(); //5. set the size of the frame and make it visible frame.setSize(WIDTH, HEIGHT); frame.setVisible(true); } // Called once for OpenGL initialization public void init(GLDrawable drawable) { //6. specify a drawing color: red gl.glColor3f(1.0f, 0.0f, 0.0f); } // Called for handling reshaped drawing area public void reshape( GLDrawable drawable, int x, int y, int width, int height) { //7. specify the drawing area (frame) coordinates gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho(0, width, 0, height, -1.0, 1.0); } // Called for OpenGL rendering every reshape public void display(GLDrawable drawable) { //8. specify to draw a point gl.glBegin(GL.GL_POINTS); gl.glVertex2i(WIDTH/2, HEIGHT/2); gl.glEnd(); } // called if display mode or device are changed public void displayChanged( GLDrawable drawable, boolean modeChanged, boolean deviceChanged) { } }