/** * This is a short demo illustrating the basic structure * of a JOGL application. It corresponds to the first * attempt example from Hill */ import java.awt.*; import java.awt.event.*; import javax.media.opengl.*; import javax.media.opengl.glu.*; public class firstAttempt extends Frame implements GLEventListener{ public firstAttempt() { GLCapabilities caps = new GLCapabilities(); GLCanvas canvas = new GLCanvas(caps); canvas.addGLEventListener(this); add("Center", canvas); setSize(400,300); setVisible(true); } public static void main( String args[]) { firstAttempt frame = new firstAttempt(); //exit if frame's close box is clicked frame.addWindowListener( new WindowAdapter() { public void windowClosed(WindowEvent e){ System.exit(0); } public void windowClosing(WindowEvent e) { windowClosed(e); } } ); } /* The functions below are required because we are a GLEventListener. We could also have put them in another class and put that class in the addGLEventListener method above. */ /** * Executed exactly once to initialize the * associated GLDrawable */ public void init(GLAutoDrawable drawable) { // print every openGL call for debugging purposes drawable.setGL(new TraceGL(drawable.getGL(), System.err)); GL gl = drawable.getGL(); /** * Set the background colour when the GLDrawable * is cleared */ gl.glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); //white /** Set the drawing colour to black */ gl.glColor3f( 0.0f, 0.0f, 0.0f ); gl.glPointSize(4.0f); //a 'dot' is 4 by 4 pixels } /** * Executed if the associated GLDrawable is resized */ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { GL gl = drawable.getGL(); gl.glViewport( 0, 0, width, height ); gl.glMatrixMode( GL.GL_PROJECTION ); gl.glLoadIdentity(); gl.glOrtho(0, 400, 0, 300, -1, 1); } /** This method handles the painting of the GLDrawable */ public void display(GLAutoDrawable drawable) { GL gl = drawable.getGL(); /** Clear the colour buffer */ gl.glClear( GL.GL_COLOR_BUFFER_BIT ); /** Draw some dots */ gl.glBegin( GL.GL_POINTS ); gl.glVertex2i( 100,50 ); gl.glVertex2i( 100,130 ); gl.glVertex2i( 150,130 ); gl.glEnd(); } /** This method handles things if display depth changes */ public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged){ } }