import net.java.games.jogl.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.event.*; public class Main { public Main(){ JFrame frame = new JFrame("Test Frame"); frame.setBounds(10, 10, 500, 500); frame.getContentPane().setLayout(new BorderLayout()); GLCapabilities glCaps = new GLCapabilities(); glCaps.setRedBits(8); glCaps.setBlueBits(8); glCaps.setGreenBits(8); glCaps.setAlphaBits(8); GLJPanel panel = GLDrawableFactory.getFactory().createGLJPanel(glCaps); frame.getContentPane().add(panel, BorderLayout.CENTER); JPanel p = new JPanel(new FlowLayout()); JButton b = new JButton("Test Me"); p.add(b); frame.getContentPane().add(p, BorderLayout.WEST); panel.addGLEventListener(new GLContextRenderer()); final Animator animator = new Animator(panel); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { animator.stop(); System.exit(0); } }); frame.setVisible(true); animator.start(); } public static void main(String[] args) { new Main(); } } class GLContextRenderer implements GLEventListener { GL gl; GLDrawable glDrawable; float xRot; public void init(GLDrawable glDrawable) { this.gl = glDrawable.getGL(); this.glDrawable = glDrawable; gl.glShadeModel(GL.GL_SMOOTH); // Enable Smooth Shading gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background gl.glClearDepth(1.0f); // Depth Buffer Setup gl.glEnable(GL.GL_DEPTH_TEST); // Enables Depth Testing gl.glDepthFunc(GL.GL_LEQUAL); // The Type Of Depth Testing To Do gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); // Really Nice Perspective Calculations gl.glEnable(GL.GL_TEXTURE_2D); } public void display(GLDrawable glDrawable) { gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT ); gl.glLoadIdentity(); gl.glTranslatef(0.0f, 0.0f, -6.0f); gl.glColor3f(1.0f, 0.0f, 0.0f ); gl.glRotatef(xRot, 1.0f, 0.0f, 0.0f); gl.glBegin( GL.GL_TRIANGLES ); gl.glVertex3f( 0.0f, 0.0f, 0.0f ); gl.glVertex3f( 1.0f, 0.0f, 0.0f ); gl.glVertex3f( 1.0f, 1.0f, 0.0f ); gl.glEnd(); xRot += .2f; } public void reshape(GLDrawable glDrawable, int x, int y, int width, int height) { final GLU glu = glDrawable.getGLU(); if (height <= 0) // avoid a divide by zero error! height = 1; final float h = (float)width / (float)height; gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(45.0f, h, 1.0, 20.0); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); } public void displayChanged(GLDrawable glDrawable, boolean b, boolean b1) { //To change body of implemented methods use File | Settings | File Templates. } }