/*
* SimpleGLJPanel.java
*
* Created on 30. Juli 2008, 16:18
*/
package org.yourorghere;
import com.sun.opengl.util.Animator;
import java.awt.EventQueue;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLJPanel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
/**
*
* @author cylab
* @author mbien
*/
public class SimpleGLJPanel extends JFrame {
private Animator animator;
/** Creates new form MainFrame */
public SimpleGLJPanel() {
initComponents();
setTitle("Simple JOGL Application");
panel.addGLEventListener(new GLRenderer());
animator = new Animator(panel);
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// Run this on another thread than the AWT event queue to
// make sure the call to Animator.stop() completes before
// exiting
new Thread(new Runnable() {
public void run() {
animator.stop();
System.exit(0);
}
}).start();
}
});
}
@Override
public void setVisible(boolean show){
if(!show)
animator.stop();
super.setVisible(show);
if(!show)
animator.start();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
JLabel label = new JLabel();
panel = new GLJPanel(createGLCapabilites());
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
label.setText("Below you see a GLJPanel");
GroupLayout panelLayout = new GroupLayout(panel);
panel.setLayout(panelLayout);
panelLayout.setHorizontalGroup(
panelLayout.createParallelGroup(Alignment.LEADING)
.addGap(0, 380, Short.MAX_VALUE)
);
panelLayout.setVerticalGroup(
panelLayout.createParallelGroup(Alignment.LEADING)
.addGap(0, 258, Short.MAX_VALUE)
);
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(Alignment.LEADING)
.addComponent(panel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(label))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(label)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(panel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* Called from within initComponents().
* hint: to customize the generated code choose 'Customize Code' in the contextmenu
* of the selected UI Component you wish to cutomize in design mode.
* @return Returns customized GLCapabilities.
*/
private GLCapabilities createGLCapabilites() {
GLProfile profile = GLProfile.get(GLProfile.GL2);
GLCapabilities capabilities = new GLCapabilities(profile);
capabilities.setHardwareAccelerated(true);
// try to enable 2x anti aliasing - should be supported on most hardware
capabilities.setNumSamples(2);
capabilities.setSampleBuffers(true);
return capabilities;
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
// Run this in the AWT event thread to prevent deadlocks and race conditions
EventQueue.invokeLater(new Runnable() {
public void run() {
// switch to system l&f for native font rendering etc.
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception ex) {
Logger.getLogger(getClass().getName()).log(Level.INFO, "can not enable system look and feel", ex);
}
SimpleGLJPanel frame = new SimpleGLJPanel();
frame.setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private GLJPanel panel;
// End of variables declaration//GEN-END:variables
}