28package com.jogamp.opengl.test.junit.jogl.awt;
30import java.awt.BorderLayout;
31import java.awt.Container;
32import java.awt.Dimension;
33import java.awt.GridLayout;
34import java.awt.event.ActionEvent;
35import java.lang.reflect.InvocationTargetException;
36import java.util.Arrays;
38import com.jogamp.opengl.GL;
39import com.jogamp.opengl.GL2;
40import com.jogamp.opengl.GLAutoDrawable;
41import com.jogamp.opengl.GLCapabilities;
42import com.jogamp.opengl.GLCapabilitiesImmutable;
43import com.jogamp.opengl.GLEventListener;
44import com.jogamp.opengl.GLProfile;
45import com.jogamp.opengl.awt.GLJPanel;
47import javax.swing.AbstractAction;
48import javax.swing.JFrame;
49import javax.swing.JPanel;
50import javax.swing.JToolBar;
51import javax.swing.SwingUtilities;
52import javax.swing.WindowConstants;
54import org.junit.Assert;
55import org.junit.Assume;
56import org.junit.BeforeClass;
57import org.junit.FixMethodOrder;
59import org.junit.runners.MethodSorters;
61import com.jogamp.opengl.test.junit.util.MiscUtils;
62import com.jogamp.opengl.test.junit.util.UITestCase;
63import com.jogamp.opengl.util.FPSAnimator;
64import com.jogamp.opengl.util.GLReadBufferUtil;
65import com.jogamp.opengl.util.texture.TextureIO;
70@FixMethodOrder(MethodSorters.NAME_ASCENDING)
78 static final Dimension gljPanelSize =
new Dimension(800, 600);
80 static long duration = 500;
83 final JFrame[] frame = {
null };
84 final JPanel[] container = {
null };
85 final GLJPanel[] glJPanel = {
null };
89 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
90 @SuppressWarnings(
"serial")
93 final JFrame _frame =
new JFrame(
"Testing");
95 _frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
96 final Container content = _frame.getContentPane();
97 content.setLayout(
new BorderLayout());
99 final JToolBar toolbar =
new JToolBar();
101 final JPanel _container =
new JPanel();
102 container[0] = _container;
103 _container.setLayout(
new GridLayout(1, 1));
105 glJPanel[0] = _glJPanel;
107 _glJPanel.setPreferredSize(gljPanelSize);
108 _container.add(_glJPanel);
109 animator.
add(_glJPanel);
111 toolbar.add(
new AbstractAction(
"Remove and add") {
113 public void actionPerformed(
final ActionEvent e) {
114 System.err.println(
"XXX: Remove");
115 _container.removeAll();
116 System.err.println(
"XXX: ReAdd.0: glJPanel-Size: "+glJPanel[0].getSize());
117 _container.add(_glJPanel);
118 _glJPanel.invalidate();
120 System.err.println(
"XXX: ReAdd.X: glJPanel-Size: "+glJPanel[0].getSize());
124 content.add(toolbar, BorderLayout.NORTH);
125 content.add(_container, BorderLayout.CENTER);
128 _frame.setLocationRelativeTo(
null);
129 _frame.setVisible(
true);
131 }
catch(
final Throwable throwable ) {
132 throwable.printStackTrace();
133 Assume.assumeNoException( throwable );
139 }
catch (
final InterruptedException e1) {
140 e1.printStackTrace();
143 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
146 System.err.println(
"XXX: Remove");
147 container[0].removeAll();
148 System.err.println(
"XXX: ReAdd.0: glJPanel-Size: "+glJPanel[0].getSize());
149 container[0].add(glJPanel[0]);
150 glJPanel[0].invalidate();
152 System.err.println(
"XXX: ReAdd.X: glJPanel-Size: "+glJPanel[0].getSize());
155 }
catch(
final Throwable throwable ) {
156 throwable.printStackTrace();
157 Assume.assumeNoException( throwable );
160 Thread.sleep(duration);
161 }
catch (
final InterruptedException e1) {
162 e1.printStackTrace();
165 SwingUtilities.invokeAndWait(
new Runnable() {
170 }
catch (
final Exception e1) {
171 e1.printStackTrace();
176 public void test00() throws InterruptedException, InvocationTargetException {
179 System.err.println(
"Exp GL_Viewport: "+Arrays.toString(exp_gl_viewport));
180 System.err.println(
"Has GL_Viewport: "+Arrays.toString(has_gl_viewport));
181 Assert.assertArrayEquals(exp_gl_viewport, has_gl_viewport);
183 final int[] exp_gl_viewport = { -1, -1, -1, -1 };
184 final int[] has_gl_viewport = { -1, -1, -1, -1 };
186 public static void main(
final String[] args) {
187 for(
int i=0; i<args.length; i++) {
188 if(args[i].equals(
"-time")) {
200 private double theta = 0;
201 private double s = 0;
202 private double c = 0;
203 private boolean doScreenshot =
false;
205 public MyRotTriangle() {
213 snapshot(sn++,
null, drawable.
getGL(), screenshot, TextureIO.PNG,
null);
214 doScreenshot =
false;
220 System.err.println(
"GLEL dispose");
226 ", "+drawable.getClass().getSimpleName()+
235 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
final int w,
final int h) {
236 exp_gl_viewport[0] = x;
237 exp_gl_viewport[1] = y;
238 exp_gl_viewport[2] = w;
239 exp_gl_viewport[3] = h;
240 System.err.println(
"GLEL reshape: Surface "+drawable.getSurfaceWidth()+
"x"+drawable.getSurfaceWidth()+
241 ", reshape "+x+
"/"+y+
" "+w+
"x"+h);
242 final GL2 gl = drawable.getGL().getGL2();
243 gl.glGetIntegerv(GL.GL_VIEWPORT, has_gl_viewport, 0);
246 private void update() {
252 private void render(
final GLAutoDrawable drawable) {
253 final GL2 gl = drawable.getGL().getGL2();
255 gl.glClear(GL.GL_COLOR_BUFFER_BIT);
258 gl.glBegin(GL.GL_TRIANGLES);
259 gl.glColor3f(1, 0, 0);
260 gl.glVertex2d(-c, -c);
261 gl.glColor3f(0, 1, 0);
263 gl.glColor3f(0, 0, 1);
264 gl.glVertex2d(s, -s);
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
static void initSingleton()
Static initialization of JOGL.
A lightweight Swing component which provides OpenGL rendering support.
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Remove and re-add a GLJPanel from its Swing parent.
static void main(final String[] args)
void test(final GLCapabilitiesImmutable caps, final GLEventListener demo)
static long atol(final String str, final long def)
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
An Animator subclass which attempts to achieve a target frames-per-second rate to avoid using all CPU...
final synchronized boolean start()
Starts this animator, if not running.
Utility to read out the current FB to TextureData, optionally writing the data back to a texture obje...
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
int getSwapInterval()
Return the current swap interval.
Specifies an immutable set of OpenGL capabilities.
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
void repaint()
Schedules a repaint of the component at some point in the future.