package joglsamples;
import com.jogamp.opengl.*;
import com.jogamp.opengl.awt.GLJPanel;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@SuppressWa
...
package joglsamples;
import com.jogamp.opengl.*;
import com.jogamp.opengl.awt.GLJPanel;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@SuppressWarnings("serial")
public class My3DScene extends JPanel implements GLEventListener
{
public static void main(String[] args)
{
JFrame window = new JFrame("My 3D Graphics Scene");
My3DScene panel = new My3DScene();
window.setContentPane(panel);
window.pack(); // Set window size based on the preferred sizes of its contents.
window.setResizable(false);
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
window.setLocation( // Center window on screen.
(screen.width - window.getWidth())/2,
(screen.height - window.getHeight())/2 );
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setVisible(true);
}
private MyShapes myShapes = new MyShapes(); // An instance of the MyShpaes class
containing all the shapes that I have drawn.
private int frameNumber; // Current frame number, increases by 1 in each frame.
private Timer animationTimer;
public My3DScene()
{
GLCapabilities caps = new GLCapabilities(null);
GLJPanel display = new GLJPanel(caps);
display.setPreferredSize( new Dimension(640,480) ); //sets display size of the
viewing screen to 640-by-480
display.addGLEventListener(this);
setLayout(new BorderLayout());
add(display, BorderLayout.CENTER);
//start the animation
animationTimer = new Timer(20, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
frameNumber++;
display.repaint();
}
});
animationTimer.start();
}
//Methods of the GLEventListener interface
public void init(GLAutoDrawable drawable)
{
// called when the panel is created
GL2 gl2 = drawable.getGL().getGL2();
gl2.glEnable(GL2.GL_DEPTH_TEST); // Required for 3D drawing, not usually for 2D.
gl2.glLineWidth(2);
[Show More]