There seems to be an error somewhere in the code but I am not sure where. Anyone can take a look? Thanks
// test.java
// Import classes from some necessary places
import java.awt.;
import java.awt.event.;
import javax.swing.;
import javax.swing.event.;
import net.java.games.jogl.*;
public class test extends JFrame implements WindowListener,
GLEventListener
{
// enables gl and glu calls
GL gl;
GLU glu;
// The OpenGL component to render onto
public GLCanvas glc = null;
// set up GUI (constructor)
public test()
{
super( "Canvas" );
// Set the layout of the frame
final Container c = getContentPane();
c.setLayout(new BorderLayout());
// create and set capabilities
GLCapabilities cap = new GLCapabilities();
cap.setDoubleBuffered(true);
cap.setDepthBits(12);
cap.setRedBits(24);
cap.setGreenBits(24);
cap.setBlueBits(24);
cap.setAlphaBits(24);
// create canvas component
glc = GLDrawableFactory.getFactory().createGLCanvas(cap);
glc.setSize(300,300);
// Add the Component into the window
c.add( "Center", glc );
pack(); show();
glc.requestFocus();
// Add Windows Listener to the component
this.addWindowListener( this );
//Add GLEventListener to handle GL events
glc.addGLEventListener(this);
}
public void init(GLDrawable drawable)
{
gl = drawable.getGL();
glu = drawable.getGLU();
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glShadeModel(GL.GL_SMOOTH);
gl.glEnable(GL.GL_DEPTH_TEST);
}
public void display(GLDrawable drawable)
{
// clear colour and depth buffer
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
// Set drawing colour to white
gl.glColor3f(1.0f,1.0f,1.0f);
// Draw a rectangle
gl.glBegin(GL.GL_POLYGON);
gl.glVertex3f(0.25f,0.25f,0.0f);
gl.glVertex3f(0.75f,0.25f,0.0f);
gl.glVertex3f(0.75f,0.75f,0.0f);
gl.glVertex3f(0.25f,0.75f,0.0f);
gl.glEnd();
}
public void reshape(GLDrawable drawable, int x, int y, int width, int height)
{
gl.glViewport (0, 0, width, height);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
}
public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
// WindowListener methods
public void windowActivated( WindowEvent evt ) {}
public void windowClosed( WindowEvent evt ) {}
public void windowClosing( WindowEvent evt )
{
System.exit( 0 );
}
public void windowDeactivated( WindowEvent evt ) {}
public void windowDeiconified( WindowEvent evt ) {}
public void windowIconified( WindowEvent evt ) {}
public void windowOpened( WindowEvent evt ) {}
public static void main( String args[] )
{
// Set the look and feel of application
try
{
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
} catch (Exception e){}
test application = new test();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}