Programming > STUDY GUIDE > University of Maryland, University CollegeCMSC 405My3DScene.java (All)
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.ActionLi ... stener; @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]
Last updated: 3 years ago
Preview 1 out of 4 pages
Buy this document to get the full access instantly
Instant Download Access after purchase
Buy NowInstant download
We Accept:
Can't find what you want? Try our AI powered Search
Connected school, study & course
About the document
Uploaded On
Jun 08, 2021
Number of pages
4
Written in
All
This document has been written for:
Uploaded
Jun 08, 2021
Downloads
0
Views
81
Scholarfriends.com Online Platform by Browsegrades Inc. 651N South Broad St, Middletown DE. United States.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Scholarfriends · High quality services·