package com.momega.spacesimulator.onetriangle; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLEventListener; import javax.media.opengl.GLProfile; import javax.media.opengl.GLCapabilities; import javax.media.opengl.awt.GLCanvas; import javax.swing.JFrame; import java.awt.BorderLayout; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; /** * A minimal program that draws with JOGL in a Swing JFrame using the AWT GLCanvas. * * @author Wade Walker */ public class OneTriangleSwingGLCanvas { public static void main( String [] args ) { GLProfile glprofile = GLProfile.getDefault(); GLCapabilities glcapabilities = new GLCapabilities( glprofile ); final GLCanvas glcanvas = new GLCanvas( glcapabilities ); glcanvas.addGLEventListener( new GLEventListener() { @Override public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) { OneTriangle.setup( glautodrawable.getGL().getGL2(), width, height ); } @Override public void init( GLAutoDrawable glautodrawable ) { } @Override public void dispose( GLAutoDrawable glautodrawable ) { } @Override public void display( GLAutoDrawable glautodrawable ) { OneTriangle.render( glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight() ); } }); final JFrame jframe = new JFrame( "One Triangle Swing GLCanvas" ); jframe.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent windowevent ) { jframe.dispose(); System.exit( 0 ); } }); jframe.getContentPane().add( glcanvas, BorderLayout.CENTER ); jframe.setSize( 640, 480 ); jframe.setVisible( true ); } }