import java.awt.GraphicsDevice ; import javax.media.opengl.GL ; import javax.media.opengl.GL2 ; import javax.media.opengl.GLAutoDrawable ; import javax.media.opengl.GLCapabilities ; import javax.media.opengl.GLCapabilitiesChooser ; import javax.media.opengl.GLContext ; import javax.media.opengl.GLEventListener ; import javax.media.opengl.awt.GLCanvas ; import javax.media.opengl.awt.GLJPanel ; import javax.media.opengl.fixedfunc.GLMatrixFunc ; public class BigRedXCanvas extends GLCanvas implements GLEventListener { public BigRedXCanvas() { this( null ) ; } public BigRedXCanvas( GLCapabilities capabilities ) { this( capabilities, null, null, null ) ; } public BigRedXCanvas( GLCapabilities capabilities, GLCapabilitiesChooser chooser, GLContext shareWith, GraphicsDevice device ) { super( capabilities, chooser, shareWith, device ) ; addGLEventListener( this ) ; } //////////////////////////////////////////////////////////////////////////// public void init( GLAutoDrawable drawable ) { GL2 gl = drawable.getGL().getGL2() ; gl.setSwapInterval( 1 ) ; System.err.println( "INIT GL IS: " + gl.getClass().getName() ) ; System.err.println( "GL_VENDOR: " + gl.glGetString( GL.GL_VENDOR ) ) ; System.err.println( "GL_RENDERER: " + gl.glGetString( GL.GL_RENDERER ) ) ; System.err.println( "GL_VERSION: " + gl.glGetString( GL.GL_VERSION ) ) ; } //////////////////////////////////////////////////////////////////////////// public void reshape( GLAutoDrawable drawable, int x, int y, int width, int height ) { GL2 gl = drawable.getGL().getGL2() ; gl.glMatrixMode( GLMatrixFunc.GL_PROJECTION ) ; gl.glLoadIdentity() ; gl.glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ) ; gl.glMatrixMode( GLMatrixFunc.GL_MODELVIEW ) ; gl.glLoadIdentity() ; } //////////////////////////////////////////////////////////////////////////// public void display( GLAutoDrawable drawable ) { GL2 gl = drawable.getGL().getGL2() ; if( ( drawable instanceof GLJPanel ) && !((GLJPanel) drawable).isOpaque() && ((GLJPanel) drawable).shouldPreserveColorBufferIfTranslucent() ) { gl.glClear( GL.GL_DEPTH_BUFFER_BIT ) ; } else { gl.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT ) ; } gl.glColor4f( 1.0f, 0.0f, 0.0f, 1.0f ) ; for( int n = 0 ; n < 1000 ; ++n ) // This is only here to spend extra time. { gl.glPushMatrix() ; { gl.glBegin( GL2.GL_LINES ) ; { gl.glVertex2f( -1.0f, -1.0f ) ; gl.glVertex2f( 1.0f, 1.0f ) ; gl.glVertex2f( -1.0f, 1.0f ) ; gl.glVertex2f( 1.0f, -1.0f ) ; } gl.glEnd() ; } gl.glPopMatrix() ; } } //////////////////////////////////////////////////////////////////////////// public void dispose( GLAutoDrawable drawable ) { } //////////////////////////////////////////////////////////////////////////// }