JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
Bug735Inv4AWT.java
Go to the documentation of this file.
1package com.jogamp.opengl.test.bugs;
2
3import java.awt.Color;
4import java.awt.Frame;
5import java.awt.GraphicsDevice;
6import java.awt.GraphicsEnvironment;
7import java.awt.Insets;
8import java.awt.Rectangle;
9import java.awt.event.WindowAdapter;
10import java.awt.event.WindowEvent;
11
12import com.jogamp.opengl.GLAutoDrawable;
13import com.jogamp.opengl.GLCapabilities;
14import com.jogamp.opengl.GLEventListener;
15import com.jogamp.opengl.GLProfile;
16import com.jogamp.opengl.awt.GLCanvas;
17import javax.swing.SwingUtilities;
18
19import com.jogamp.newt.awt.NewtCanvasAWT;
20import com.jogamp.newt.opengl.GLWindow;
21import com.jogamp.opengl.test.junit.jogl.demos.es2.LandscapeES2;
22import com.jogamp.opengl.test.junit.util.MiscUtils;
23import com.jogamp.opengl.test.junit.util.UITestCase;
24import com.jogamp.opengl.util.Animator;
25import com.jogamp.opengl.util.AnimatorBase;
26
27/**
28 * Difference to orig. Bug735Inv0AppletAWT:
29 * <pre>
30 * - Use GLEventListener
31 * - Add GLEventListener to GLAutoDrawable
32 * - Use GLAutoDrawable.display() instead of GLAutoDrawable.invoke(true, GLRunnable { init / render })
33 * - Removed MANUAL_FRAME_HANDLING, obsolete due to GLAutoDrawable/GLEventListener
34 * - Use Animator
35 * - Remove component sizes, use frame based size via validate
36 * - Run frame validation/visibility on AWT-EDT
37 * - Add Wait-For-Key after init (perf-test)
38 * - Remove intermediate applet!
39 * </pre>
40 * OSX Results:
41 * <pre>
42 * - Visible content
43 * - Fluent animation
44 * </pre>
45 */
46public class Bug735Inv4AWT {
47 static public final int AWT = 0;
48 static public final int NEWT = 1;
49
50 static public final int APPLET_WIDTH = 500;
51 static public final int APPLET_HEIGHT = 290;
52 static public final int TOOLKIT = NEWT;
53 static public final boolean IGNORE_AWT_REPAINT = false;
54 static public boolean USE_ECT = false;
55 static public int SWAP_INTERVAL = 1;
56
57 //////////////////////////////////////////////////////////////////////////////
58
59 static boolean waitForKey = false;
60 static private Frame frame;
61 static private Bug735Inv4AWT applet;
62 private GLCanvas awtCanvas;
63 private GLWindow newtWindow;
64 private GLAutoDrawable glad;
65 private NewtCanvasAWT newtCanvas;
66 private GLEventListener demo;
67 private AnimatorBase animator;
68
69 private int width;
70 private int height;
71
72 public void init() {
73 width = APPLET_WIDTH;
74 height = APPLET_HEIGHT;
75 initGL();
76 }
77
78 public void start() {
79 initDraw();
80 animator.start();
81 animator.setUpdateFPSFrames(60, System.err);
82 }
83
84 private void initGL() {
85 final GLProfile profile = GLProfile.getDefault();
86 final GLCapabilities caps = new GLCapabilities(profile);
87 caps.setBackgroundOpaque(true);
88 caps.setOnscreen(true);
89 caps.setSampleBuffers(false);
90
91 if (TOOLKIT == AWT) {
92 awtCanvas = new GLCanvas(caps);
93 awtCanvas.setBackground(new Color(0xFFCCCCCC, true));
94 awtCanvas.setFocusable(true);
95
97 awtCanvas.setIgnoreRepaint(true);
98 }
99 glad = awtCanvas;
100 } else if (TOOLKIT == NEWT) {
101 newtWindow = GLWindow.create(caps);
102 newtCanvas = new NewtCanvasAWT(newtWindow);
103 newtCanvas.setBackground(new Color(0xFFCCCCCC, true));
104 newtCanvas.setFocusable(true);
105
106 if (IGNORE_AWT_REPAINT) {
107 newtCanvas.setIgnoreRepaint(true);
108 }
109 glad = newtWindow;
110 }
111
112 demo = new LandscapeES2(SWAP_INTERVAL);
113 // demo = new GearsES2(SWAP_INTERVAL);
114 glad.addGLEventListener(demo);
115 animator = new Animator(glad);
117 }
118
119 private void initDraw() {
120 if (TOOLKIT == AWT) {
121 if (awtCanvas.getDelegatedDrawable().isRealized()) {
122 // Request the focus here as it cannot work when the window is not visible
123 awtCanvas.requestFocus();
124 }
125 } else if (TOOLKIT == NEWT) {
126 // newtCanvas.repaint();
127 // Force the realization
128 // newtWindow.display();
129 if (newtWindow.isRealized()) {
130 // Request the focus here as it cannot work when the window is not visible
131 newtCanvas.requestFocus();
132 }
133 }
134 }
135
136 static public void main(final String[] args) {
137 for(int i=0; i<args.length; i++) {
138 if(args[i].equals("-vsync")) {
139 i++;
141 } else if(args[i].equals("-exclctx")) {
142 USE_ECT = true;
143 } else if(args[i].equals("-wait")) {
144 waitForKey = true;
145 }
146 }
147 System.err.println("swapInterval "+SWAP_INTERVAL);
148 System.err.println("exclusiveContext "+USE_ECT);
149 if(waitForKey) {
150 UITestCase.waitForKey("Start");
151 }
152
153 final GraphicsEnvironment environment =
154 GraphicsEnvironment.getLocalGraphicsEnvironment();
155 final GraphicsDevice displayDevice = environment.getDefaultScreenDevice();
156
157 frame = new Frame(displayDevice.getDefaultConfiguration());
158 // JAU frame.setBackground(new Color(0xCC, 0xCC, 0xCC));
159 frame.setTitle("TestBug735Inv4AWT");
160
161 // This allows to close the frame.
162 frame.addWindowListener(new WindowAdapter() {
163 public void windowClosing(final WindowEvent e) {
164 System.exit(0);
165 }
166 });
167
168 applet = new Bug735Inv4AWT();
169 applet.init();
170
171 if (TOOLKIT == AWT) {
172 frame.add(applet.awtCanvas);
173 } else if (TOOLKIT == NEWT) {
174 frame.add(applet.newtCanvas);
175 }
176 // frame.pack();
177 // frame.setResizable(false);
178
179 final Insets insets = frame.getInsets();
180 final int windowW = applet.width + insets.left + insets.right;
181 final int windowH = applet.height + insets.top + insets.bottom;
182
183 try {
184 SwingUtilities.invokeAndWait(new Runnable() {
185 public void run() {
186 frame.setSize(windowW, windowH);
187 frame.validate();
188 // frame.pack();
189 final Rectangle screenRect = displayDevice.getDefaultConfiguration().getBounds();
190 frame.setLocation(screenRect.x + (screenRect.width - applet.width) / 2,
191 screenRect.y + (screenRect.height - applet.height) / 2);
192
193 frame.setVisible(true);
194 }
195 });
196 } catch (final Exception e) {
197 e.printStackTrace();
198 }
199
200 applet.start();
201 }
202}
void setBackgroundOpaque(final boolean opaque)
Sets whether the surface shall be opaque or translucent.
void setOnscreen(final boolean onscreen)
Sets whether the surface shall be on- or offscreen.
AWT Canvas containing a NEWT Window using native parenting.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
Specifies a set of OpenGL capabilities.
void setSampleBuffers(final boolean enable)
Defaults to false.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
Definition: GLProfile.java:739
A heavyweight AWT component which provides OpenGL rendering support.
Definition: GLCanvas.java:170
final GLDrawable getDelegatedDrawable()
If the implementation uses delegation, return the delegated GLDrawable instance, otherwise return thi...
Definition: GLCanvas.java:1161
static void main(final String[] args)
static int atoi(final String str, final int def)
Definition: MiscUtils.java:57
Base implementation of GLAnimatorControl
final synchronized Thread setExclusiveContext(final Thread t)
Dedicate all GLAutoDrawable's context to the given exclusive context thread.
final void setUpdateFPSFrames(final int frames, final PrintStream out)
boolean start()
Starts this animator, if not running.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
boolean isRealized()
Returns true if this drawable is realized, otherwise false.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.