JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
GLJPanelsAndGLCanvasDemoGL2Applet.java
Go to the documentation of this file.
1/**
2 * Copyright 2013 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28package com.jogamp.opengl.test.junit.jogl.demos.gl2.awt;
29
30import java.awt.ComponentOrientation;
31import java.awt.Dimension;
32import java.awt.GridLayout;
33import java.awt.event.WindowAdapter;
34import java.awt.event.WindowEvent;
35
36import com.jogamp.opengl.awt.GLCanvas;
37import com.jogamp.opengl.awt.GLJPanel;
38import javax.swing.JApplet;
39import javax.swing.JLabel;
40import javax.swing.JPanel;
41import javax.swing.JFrame;
42import javax.swing.SwingConstants;
43
44import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears;
45import com.jogamp.opengl.test.junit.jogl.demos.gl2.Teapot;
46import com.jogamp.opengl.util.Animator;
47
48/**
49 */
50public class GLJPanelsAndGLCanvasDemoGL2Applet extends JApplet {
51
52 private static final long serialVersionUID = 1L;
53
54 private Animator[] animator;
55
56 public static JFrame frame;
57 public static JPanel appletHolder;
58 public static boolean isApplet = true;
59
60 static public void main(final String args[]) {
61 isApplet = false;
62
63 final JApplet myApplet = new GLJPanelsAndGLCanvasDemoGL2Applet();
64
65 appletHolder = new JPanel();
66
67 frame = new JFrame("Bug818GLJPanelApplet");
68 frame.getContentPane().add(myApplet);
69
70 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
71 frame.addWindowListener(new WindowAdapter() {
72 public void windowClosing(final WindowEvent e) {
73 System.exit(0);
74 }
75 });
76
77 try {
78 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
79 public void run() {
80 myApplet.init();
81 frame.validate();
82 frame.pack();
83 frame.setVisible(true);
84 } } );
85 } catch( final Throwable throwable ) {
86 throwable.printStackTrace();
87 }
88
89 myApplet.start();
90 }
91
92
93 @Override
94 public void init() {
95
96 final JPanel panel = new JPanel();
97 panel.setLayout(new GridLayout(3, 2));
98 System.err.println("Pre Orientation L2R: "+panel.getComponentOrientation().isLeftToRight());
99 panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
100 System.err.println("Post Orientation L2R: "+panel.getComponentOrientation().isLeftToRight());
101 setContentPane(panel);
102
103 animator = new Animator[3*2];
104 int animIdx = 0;
105
106 panel.add(new JLabel("GLJPanel Auto V-Flip", SwingConstants.CENTER));
107 {
108 {
109 final GLJPanel gljPanel = new GLJPanel();
110 gljPanel.addGLEventListener(new Teapot());
111 animator[animIdx++] = new Animator(gljPanel);
112 gljPanel.setPreferredSize(new Dimension(300, 300));
113 panel.add(gljPanel);
114 }
115 {
116 final GLJPanel gljPanel = new GLJPanel();
117 gljPanel.addGLEventListener(new Gears(0));
118 animator[animIdx++] = new Animator(gljPanel);
119 gljPanel.setPreferredSize(new Dimension(300, 300));
120 panel.add(gljPanel);
121 }
122 }
123 panel.add(new JLabel("GLJPanel User V-Flip", SwingConstants.CENTER));
124 {
125 {
126 final GLJPanel gljPanel = new GLJPanel();
128 gljPanel.addGLEventListener(new Teapot());
129 animator[animIdx++] = new Animator(gljPanel);
130 gljPanel.setPreferredSize(new Dimension(300, 300));
131 panel.add(gljPanel);
132 }
133 {
134 final GLJPanel gljPanel = new GLJPanel();
136 gljPanel.addGLEventListener(new Gears(0));
137 animator[animIdx++] = new Animator(gljPanel);
138 gljPanel.setPreferredSize(new Dimension(300, 300));
139 panel.add(gljPanel);
140 }
141 }
142
143 panel.add(new JLabel("GLCanvas", SwingConstants.CENTER));
144 {
145 {
146 final GLCanvas glCanvas = new GLCanvas();
147 glCanvas.addGLEventListener(new Teapot());
148 animator[animIdx++] = new Animator(glCanvas);
149 glCanvas.setPreferredSize(new Dimension(300, 300));
150 panel.add(glCanvas);
151 }
152 {
153 final GLCanvas glCanvas = new GLCanvas();
154 glCanvas.addGLEventListener(new Gears(1));
155 animator[animIdx++] = new Animator(glCanvas);
156 glCanvas.setPreferredSize(new Dimension(300, 300));
157 panel.add(glCanvas);
158 }
159 }
160 }
161
162 @Override
163 public void start() {
164 for(int i=0; i<animator.length; i++) {
165 animator[i].start();
166 animator[i].setUpdateFPSFrames(60, System.err);
167 }
168 }
169
170 @Override
171 public void stop() {
172 for(int i=0; i<animator.length; i++) {
173 animator[i].stop();
174 }
175 }
176
177 @Override
178 public void destroy() {}
179}
180
A heavyweight AWT component which provides OpenGL rendering support.
Definition: GLCanvas.java:170
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLCanvas.java:1065
A lightweight Swing component which provides OpenGL rendering support.
Definition: GLJPanel.java:189
final void setSkipGLOrientationVerticalFlip(final boolean v)
Skip isGLOriented() based vertical flip, which usually is required by the offscreen backend,...
Definition: GLJPanel.java:1255
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLJPanel.java:989
Gears.java author: Brian Paul (converted to Java by Ron Cemer and Sven Gothel)
Definition: Gears.java:34
Adapted from http://www.java-tips.org/other-api-tips/jogl/how-to-draw-a-texture-mapped-teapot-with-au...
Definition: Teapot.java:22
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final void setUpdateFPSFrames(final int frames, final PrintStream out)
final synchronized boolean start()
Starts this animator, if not running.
Definition: Animator.java:344
final synchronized boolean stop()
Stops this animator.
Definition: Animator.java:368