aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/com')
-rw-r--r--src/test/com/jogamp/opengl/test/bugs/Bug427GLJPanel.java72
-rw-r--r--src/test/com/jogamp/opengl/test/bugs/Issue326Test1.java94
-rw-r--r--src/test/com/jogamp/opengl/test/bugs/Issue326Test2.java73
-rw-r--r--src/test/com/jogamp/opengl/test/bugs/Issue344Base.java107
-rw-r--r--src/test/com/jogamp/opengl/test/bugs/Issue344Test1.java12
-rw-r--r--src/test/com/jogamp/opengl/test/bugs/Issue344Test2.java12
-rw-r--r--src/test/com/jogamp/opengl/test/bugs/Issue344Test3.java12
-rw-r--r--src/test/com/jogamp/opengl/test/bugs/Issue344Test4.java12
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java160
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListAWT.java134
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT.java133
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT01GLn.java147
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT02WindowClosing.java111
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT03GLCanvasRecreate01.java183
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/awt/TestSwingAWT01GLn.java159
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleChooser01.java66
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleDemo01.java138
-rwxr-xr-xsrc/test/com/jogamp/opengl/test/junit/jogl/caps/TestMultisampleAWT.java122
-rwxr-xr-xsrc/test/com/jogamp/opengl/test/junit/jogl/caps/TestMultisampleNEWT.java100
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquare.java169
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquare0.java198
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader.java68
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/Gears.java353
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java122
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsGLJPanelAWT.java130
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/newt/TestGearsNEWT.java126
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/newt/TestGearsNewtAWTWrapper.java114
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/drawable/TestDrawable01NEWT.java184
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLSimple01NEWT.java143
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestTransformFeedbackVaryingsBug407NEWT.java231
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java333
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2File.java70
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2Screen.java188
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBufferBase.java91
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBufferUtil.java107
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/offscreen/Surface2File.java79
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/offscreen/TestOffscreen01NEWT.java489
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/offscreen/WindowUtilNEWT.java110
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/texture/TestTexture01AWT.java146
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java109
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java141
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle01NEWT.java264
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle02NEWT.java386
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestEventSourceNotAWTBug.java110
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java201
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java301
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows00NEWT.java133
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows01NEWT.java384
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java303
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestListenerCom01AWT.java167
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestRemoteGLWindows01NEWT.java161
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestRemoteWindow01NEWT.java139
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java140
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01NEWT.java284
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02NEWT.java187
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestWindows01NEWT.java179
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom1.java42
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom2.java48
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom3.java44
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/parenting/GLRunnableDummy.java57
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/parenting/KeyAction.java45
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java716
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aAWT.java443
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01bAWT.java205
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cAWT.java243
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java365
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02AWT.java267
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02NEWT.java235
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java203
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03bAWT.java258
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/parenting/WindowAction.java44
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/AWTFocusAdapter.java73
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/AWTKeyAdapter.java54
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/AWTMouseAdapter.java53
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java338
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/DumpGLInfo.java51
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/EventCountAdapter.java36
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/EventCountAdapterUtil.java49
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/GLSLSimpleProgram.java121
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java63
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/NEWTFocusAdapter.java64
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/NEWTKeyAdapter.java58
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/NEWTMouseAdapter.java57
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/QuitAdapter.java52
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/SingletonInstance.java143
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/UITestCase.java72
86 files changed, 13386 insertions, 0 deletions
diff --git a/src/test/com/jogamp/opengl/test/bugs/Bug427GLJPanel.java b/src/test/com/jogamp/opengl/test/bugs/Bug427GLJPanel.java
new file mode 100644
index 000000000..378952b59
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/bugs/Bug427GLJPanel.java
@@ -0,0 +1,72 @@
+package com.jogamp.opengl.test.bugs;
+
+import javax.swing.*;
+import java.awt.*;
+import javax.media.opengl.*;
+import javax.media.opengl.awt.*;
+
+public class Bug427GLJPanel extends JFrame implements GLEventListener {
+
+ public Bug427GLJPanel() {
+ super("JOGL Hello World");
+
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ setLayout(new BorderLayout());
+
+ setSize(600, 600);
+ setLocation(40, 40);
+ setVisible(true);
+
+ GLProfile glp = GLProfile.getDefault();
+ GLCapabilities caps = new GLCapabilities(glp);
+ caps.setDoubleBuffered(true);
+ caps.setHardwareAccelerated(true);
+
+ GLJPanel panel = new GLJPanel(caps);
+ panel.addGLEventListener(this);
+
+ add(panel, BorderLayout.CENTER);
+ }
+
+ public static void main(String[] args) {
+ Bug427GLJPanel demo = new Bug427GLJPanel();
+ demo.setVisible(true);
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ GL2 gl = drawable.getGL().getGL2();
+
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT);
+ gl.glBegin(GL.GL_TRIANGLES);
+
+ gl.glColor3f(1, 0, 0);
+ gl.glVertex3f(0.25f, 0.25f, 0);
+
+ gl.glColor3f(0, 1, 0);
+ gl.glVertex3f(0.5f, 0.25f, 0);
+
+ gl.glColor3f(0, 0, 1);
+ gl.glVertex3f(0.25f, 0.5f, 0);
+
+ gl.glEnd();
+ gl.glFlush();
+ }
+
+ public void init(GLAutoDrawable drawable) {
+ GL2 gl = drawable.getGL().getGL2();
+
+ gl.glClearColor(0, 0, 0, 0);
+ gl.glMatrixMode(GL2.GL_PROJECTION);
+ gl.glLoadIdentity();
+ gl.glOrtho(0, 1, 0, 1, -1, 1);
+ }
+
+ public void reshape(GLAutoDrawable glDrawable, int x, int y, int w, int h) {
+ }
+
+ public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/bugs/Issue326Test1.java b/src/test/com/jogamp/opengl/test/bugs/Issue326Test1.java
new file mode 100644
index 000000000..4c2b54755
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/bugs/Issue326Test1.java
@@ -0,0 +1,94 @@
+package com.jogamp.opengl.test.bugs;
+
+import java.awt.Frame;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.util.Random;
+
+import javax.media.opengl.GL2;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.awt.GLCanvas;
+import javax.media.opengl.glu.GLU;
+
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.awt.TextRenderer;
+
+/**
+ * Demonstrates corruption with older versions of TextRenderer. Two
+ * problems: errors when punting from glyph-based renderer to
+ * string-by-string renderer, and failure of glyph-based renderer when
+ * backing store was NPOT using GL_ARB_texture_rectangle.
+ *
+ * @author emzic
+ */
+
+public class Issue326Test1 extends Frame implements GLEventListener {
+
+ int width, height;
+
+ public static void main(String[] args) {
+ new Issue326Test1();
+ }
+
+ GLCanvas canvas;
+ TextRenderer tr ;
+
+ public Issue326Test1() {
+ super("TextTest");
+ this.setSize(800, 800);
+ canvas = new GLCanvas();
+ canvas.addGLEventListener(this);
+ add(canvas);
+
+ setVisible(true);
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ GL2 gl = drawable.getGL().getGL2();
+ gl.glClearColor(0, 0, 0, 0);
+ gl.glClear(GL2.GL_COLOR_BUFFER_BIT|GL2.GL_DEPTH_BUFFER_BIT);
+
+
+ gl.glMatrixMode(GL2.GL_PROJECTION);
+ gl.glLoadIdentity();
+ //new GLU().gluPerspective(45f, (float)width/(float)height, 0.1f, 1000f);
+ gl.glOrtho(0.0, 800, 0.0, 800, -100.0, 100.0);
+ gl.glMatrixMode(GL2.GL_MODELVIEW);
+ gl.glLoadIdentity();
+
+ tr.beginRendering(800,800);
+ tr.draw( "die Marktwirtschaft. Da regelt sich � angeblich", 16, 32);
+ tr.draw( "Hello World! This text is scrambled", 16, 16);
+ tr.endRendering();
+
+ }
+
+ public void init(GLAutoDrawable arg0) {
+ tr = new TextRenderer(new java.awt.Font("Verdana", java.awt.Font.PLAIN, 12), true, false, null, false);
+ tr.setColor(1, 1, 1 ,1);
+ }
+
+ public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) {
+ width = arg3;
+ height = arg4;
+ GL2 gl = arg0.getGL().getGL2();
+ gl.glViewport(0, 0, width, height);
+ gl.glMatrixMode(GL2.GL_PROJECTION);
+ gl.glLoadIdentity();
+ gl.glOrtho(0.0, 800, 0.0, 200, -100.0, 100.0);
+ gl.glMatrixMode(GL2.GL_MODELVIEW);
+ gl.glLoadIdentity();
+ }
+
+ public void dispose(GLAutoDrawable drawable) {}
+}
diff --git a/src/test/com/jogamp/opengl/test/bugs/Issue326Test2.java b/src/test/com/jogamp/opengl/test/bugs/Issue326Test2.java
new file mode 100644
index 000000000..8960c9658
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/bugs/Issue326Test2.java
@@ -0,0 +1,73 @@
+package com.jogamp.opengl.test.bugs;
+
+import java.awt.Font;
+import java.awt.Frame;
+import java.awt.event.*;
+import javax.media.opengl.GL2;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.awt.GLCanvas;
+
+import com.jogamp.opengl.util.awt.*;
+
+/**
+ * Another test case demonstrating corruption with older version of
+ * TextRenderer when glyphs were too big for backing store. Font and
+ * text courtesy of Patrick Murris. Adapted from Issue326Test1.
+ */
+
+public class Issue326Test2 extends Frame implements GLEventListener {
+
+ int width, height;
+
+ public static void main(String[] args) {
+ new Issue326Test2();
+ }
+
+ GLCanvas canvas;
+ TextRenderer tr;
+
+ public Issue326Test2() {
+ super("");
+ this.setSize(800, 800);
+ canvas = new GLCanvas();
+ canvas.addGLEventListener(this);
+ add(canvas);
+
+ setVisible(true);
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ GL2 gl = drawable.getGL().getGL2();
+ gl.glClearColor(0, 0, 0, 0);
+ gl.glClear(GL2.GL_COLOR_BUFFER_BIT|GL2.GL_DEPTH_BUFFER_BIT);
+
+ tr.beginRendering(drawable.getWidth(), drawable.getHeight());
+ tr.draw("LA CLAPI\u00c8RE \nAlt: 1100-1700m \nGlissement de terrain majeur", 16, 80);
+ tr.draw("dans la haute Tin\u00e9e, sur un flanc du Parc du Mercantour.", 16, 16);
+ tr.endRendering();
+
+ }
+
+ public void init(GLAutoDrawable arg0) {
+ tr = new TextRenderer(Font.decode("Arial-BOLD-64"));
+ tr.setColor(1, 1, 1 ,1);
+ }
+
+ public void reshape(GLAutoDrawable arg0, int x, int y, int w, int h) {
+ GL2 gl = arg0.getGL().getGL2();
+ gl.glMatrixMode(GL2.GL_PROJECTION);
+ gl.glLoadIdentity();
+ gl.glOrtho(0.0, w, 0.0, h, -1, 1);
+ gl.glMatrixMode(GL2.GL_MODELVIEW);
+ gl.glLoadIdentity();
+ }
+
+ public void dispose(GLAutoDrawable drawable) {}
+}
+
diff --git a/src/test/com/jogamp/opengl/test/bugs/Issue344Base.java b/src/test/com/jogamp/opengl/test/bugs/Issue344Base.java
new file mode 100644
index 000000000..c3401fec3
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/bugs/Issue344Base.java
@@ -0,0 +1,107 @@
+package com.jogamp.opengl.test.bugs;
+
+import java.awt.BorderLayout;
+import java.awt.Font;
+import java.awt.Frame;
+import java.awt.event.*;
+import java.awt.geom.*;
+
+import javax.media.opengl.GL2;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.awt.GLCanvas;
+import javax.media.opengl.glu.*;
+import com.jogamp.opengl.util.awt.TextRenderer;
+
+/** Test Code adapted from TextCube.java (in JOGL demos)
+ *
+ * @author spiraljetty
+ * @author kbr
+ */
+
+public abstract class Issue344Base implements GLEventListener
+{
+ GLU glu = new GLU();
+ TextRenderer renderer;
+
+ float textScaleFactor;
+ Font font;
+ boolean useMipMaps;
+
+ protected Issue344Base() {
+ font = new Font("default", Font.PLAIN, 200);
+ useMipMaps = true; //false
+ }
+
+ protected abstract String getText();
+
+ protected void run(String[] args) {
+ Frame frame = new Frame(getClass().getName());
+ frame.setLayout(new BorderLayout());
+
+ GLCanvas canvas = new GLCanvas();
+ canvas.addGLEventListener(this);
+ frame.add(canvas, BorderLayout.CENTER);
+
+ frame.setSize(512, 512);
+ frame.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ new Thread(new Runnable() {
+ public void run() {
+ System.exit(0);
+ }
+ }).start();
+ }
+ });
+ frame.setVisible(true);
+ }
+
+ public void init(GLAutoDrawable drawable)
+ {
+ GL2 gl = drawable.getGL().getGL2();
+
+ gl.glEnable(GL2.GL_DEPTH_TEST);
+
+ renderer = new TextRenderer(font, useMipMaps);
+
+ Rectangle2D bounds = renderer.getBounds(getText());
+ float w = (float) bounds.getWidth();
+ float h = (float) bounds.getHeight();
+ textScaleFactor = 2.0f / (w * 1.1f);
+ gl.setSwapInterval(0);
+ }
+
+ public void display(GLAutoDrawable drawable)
+ {
+ GL2 gl = drawable.getGL().getGL2();
+ gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
+
+ gl.glMatrixMode(GL2.GL_MODELVIEW);
+ gl.glLoadIdentity();
+ glu.gluLookAt(0, 0, 10,
+ 0, 0, 0,
+ 0, 1, 0);
+
+ renderer.begin3DRendering();
+ Rectangle2D bounds = renderer.getBounds(getText());
+ float w = (float) bounds.getWidth();
+ float h = (float) bounds.getHeight();
+ renderer.draw3D(getText(),
+ w / -2.0f * textScaleFactor,
+ h / -2.0f * textScaleFactor,
+ 3f,
+ textScaleFactor);
+
+ renderer.end3DRendering();
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
+ {
+ GL2 gl = drawable.getGL().getGL2();
+ gl.glMatrixMode(GL2.GL_PROJECTION);
+ gl.glLoadIdentity();
+ glu.gluPerspective(15, (float) width / (float) height, 5, 15);
+ }
+
+ public void dispose(GLAutoDrawable drawable) {}
+}
diff --git a/src/test/com/jogamp/opengl/test/bugs/Issue344Test1.java b/src/test/com/jogamp/opengl/test/bugs/Issue344Test1.java
new file mode 100644
index 000000000..f0da7cbf8
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/bugs/Issue344Test1.java
@@ -0,0 +1,12 @@
+package com.jogamp.opengl.test.bugs;
+
+public class Issue344Test1 extends Issue344Base {
+ protected String getText() {
+ // test 1 - weird artifacts appear with a large font & long string
+ return "abcdefghijklmnopqrstuvwxyz1234567890";
+ }
+
+ public static void main(String[] args) {
+ new Issue344Test1().run(args);
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/bugs/Issue344Test2.java b/src/test/com/jogamp/opengl/test/bugs/Issue344Test2.java
new file mode 100644
index 000000000..bb1acf2de
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/bugs/Issue344Test2.java
@@ -0,0 +1,12 @@
+package com.jogamp.opengl.test.bugs;
+
+public class Issue344Test2 extends Issue344Base {
+ protected String getText() {
+ // test 2 - unicode hangs program with a large font & long string
+ return "\u201Cabcdefghijklmnopqrstuvwxyz\u201D";
+ }
+
+ public static void main(String[] args) {
+ new Issue344Test2().run(args);
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/bugs/Issue344Test3.java b/src/test/com/jogamp/opengl/test/bugs/Issue344Test3.java
new file mode 100644
index 000000000..bb73d84ec
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/bugs/Issue344Test3.java
@@ -0,0 +1,12 @@
+package com.jogamp.opengl.test.bugs;
+
+public class Issue344Test3 extends Issue344Base {
+ protected String getText() {
+ // test 3 - slight rendering artifacts around very large letters
+ return "abcde";
+ }
+
+ public static void main(String[] args) {
+ new Issue344Test3().run(args);
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/bugs/Issue344Test4.java b/src/test/com/jogamp/opengl/test/bugs/Issue344Test4.java
new file mode 100644
index 000000000..de4c37a40
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/bugs/Issue344Test4.java
@@ -0,0 +1,12 @@
+package com.jogamp.opengl.test.bugs;
+
+public class Issue344Test4 extends Issue344Base {
+ protected String getText() {
+ // test 4 - unicode letter as second-to-last is rendered incorrectly
+ return "\u201CGreetings\u201D!";
+ }
+
+ public static void main(String[] args) {
+ new Issue344Test4().run(args);
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java
new file mode 100644
index 000000000..88caed357
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java
@@ -0,0 +1,160 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.acore;
+
+import com.jogamp.common.GlueGenVersion;
+import com.jogamp.common.util.VersionUtil;
+import com.jogamp.nativewindow.NativeWindowVersion;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.util.DumpGLInfo;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.media.opengl.*;
+import com.jogamp.newt.opengl.*;
+
+import com.jogamp.newt.*;
+import com.jogamp.opengl.JoglVersion;
+import java.io.IOException;
+
+public class TestGLProfile01NEWT extends UITestCase {
+
+ @Test
+ public void test00Version() throws InterruptedException {
+ System.err.println(VersionUtil.getPlatformInfo());
+ System.err.println(GlueGenVersion.getInstance());
+ System.err.println(NativeWindowVersion.getInstance());
+ System.err.println(JoglVersion.getInstance());
+ System.err.println(NewtVersion.getInstance());
+ }
+
+ @Test
+ public void test01GLProfileDefault() throws InterruptedException {
+ System.out.println("GLProfile "+GLProfile.glAvailabilityToString());
+ GLProfile glp = GLProfile.getDefault();
+ dumpVersion(glp);
+ }
+
+ @Test
+ public void test02GLProfileMaxFixedFunc() throws InterruptedException {
+ // Assuming at least one fixed profile is available
+ GLProfile glp = GLProfile.getMaxFixedFunc();
+ System.out.println("GLProfile getMaxFixedFunc(): "+glp);
+ if(glp.getName().equals(GLProfile.GL4bc)) {
+ Assert.assertTrue(GLProfile.isGL4bcAvailable());
+ Assert.assertTrue(GLProfile.isGL3bcAvailable());
+ Assert.assertTrue(GLProfile.isGL2Available());
+ Assert.assertTrue(GLProfile.isGL2ES1Available());
+ Assert.assertTrue(GLProfile.isGL2ES2Available());
+ } else if(glp.getName().equals(GLProfile.GL3bc)) {
+ Assert.assertTrue(GLProfile.isGL3bcAvailable());
+ Assert.assertTrue(GLProfile.isGL2Available());
+ Assert.assertTrue(GLProfile.isGL2ES1Available());
+ Assert.assertTrue(GLProfile.isGL2ES2Available());
+ } else if(glp.getName().equals(GLProfile.GL2)) {
+ Assert.assertTrue(GLProfile.isGL2Available());
+ Assert.assertTrue(GLProfile.isGL2ES1Available());
+ Assert.assertTrue(GLProfile.isGL2ES2Available());
+ } else if(glp.getName().equals(GLProfile.GL2ES1)) {
+ Assert.assertTrue(GLProfile.isGL2ES1Available());
+ }
+ dumpVersion(glp);
+ }
+
+ @Test
+ public void test03GLProfileMaxProgrammable() throws InterruptedException {
+ // Assuming at least one programmable profile is available
+ GLProfile glp = GLProfile.getMaxProgrammable();
+ System.out.println("GLProfile getMaxProgrammable(): "+glp);
+ if(glp.getName().equals(GLProfile.GL4)) {
+ Assert.assertTrue(GLProfile.isGL4Available());
+ Assert.assertTrue(GLProfile.isGL3Available());
+ Assert.assertTrue(GLProfile.isGL2Available());
+ Assert.assertTrue(GLProfile.isGL2ES1Available());
+ Assert.assertTrue(GLProfile.isGL2ES2Available());
+ } else if(glp.getName().equals(GLProfile.GL3)) {
+ Assert.assertTrue(GLProfile.isGL3Available());
+ Assert.assertTrue(GLProfile.isGL2Available());
+ Assert.assertTrue(GLProfile.isGL2ES1Available());
+ Assert.assertTrue(GLProfile.isGL2ES2Available());
+ } else if(glp.getName().equals(GLProfile.GL2)) {
+ Assert.assertTrue(GLProfile.isGL2Available());
+ Assert.assertTrue(GLProfile.isGL2ES1Available());
+ Assert.assertTrue(GLProfile.isGL2ES2Available());
+ } else if(glp.getName().equals(GLProfile.GL2ES2)) {
+ Assert.assertTrue(GLProfile.isGL2ES2Available());
+ }
+ dumpVersion(glp);
+ }
+
+ @Test
+ public void test04GLProfileGL2ES1() throws InterruptedException {
+ if(!GLProfile.isGL2ES1Available()) {
+ System.out.println("GLProfile GL2ES1 n/a");
+ return;
+ }
+ GLProfile glp = GLProfile.getGL2ES1();
+ System.out.println("GLProfile GL2ES1: "+glp);
+ dumpVersion(glp);
+ }
+
+ @Test
+ public void test05GLProfileGL2ES2() throws InterruptedException {
+ if(!GLProfile.isGL2ES2Available()) {
+ System.out.println("GLProfile GL2ES2 n/a");
+ return;
+ }
+ GLProfile glp = GLProfile.getGL2ES2();
+ System.out.println("GLProfile GL2ES2: "+glp);
+ dumpVersion(glp);
+ }
+
+ protected void dumpVersion(GLProfile glp) throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ GLWindow glWindow = GLWindow.create(caps);
+ Assert.assertNotNull(glWindow);
+ glWindow.setTitle("TestGLProfile01NEWT");
+
+ glWindow.addGLEventListener(new DumpGLInfo());
+
+ glWindow.setSize(128, 128);
+ glWindow.setVisible(true);
+
+ glWindow.display();
+ Thread.sleep(100);
+ glWindow.invalidate();
+ }
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestGLProfile01NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListAWT.java
new file mode 100644
index 000000000..dd3518fe3
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListAWT.java
@@ -0,0 +1,134 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.acore;
+
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLDrawableFactory;
+import javax.media.opengl.GLPbuffer;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.awt.GLCanvas;
+import com.jogamp.opengl.util.Animator;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+
+import java.awt.Frame;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestSharedContextListAWT extends UITestCase {
+ static GLProfile glp;
+ static GLCapabilities caps;
+ static int width, height;
+ GLPbuffer sharedDrawable;
+ Gears sharedGears;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ glp = GLProfile.getDefault();
+ Assert.assertNotNull(glp);
+ caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ width = 512;
+ height = 512;
+ }
+
+ private void initShared() {
+ sharedDrawable = GLDrawableFactory.getFactory(glp).createGLPbuffer(null, caps, null, width, height, null);
+ Assert.assertNotNull(sharedDrawable);
+ sharedGears = new Gears();
+ Assert.assertNotNull(sharedGears);
+ sharedDrawable.addGLEventListener(sharedGears);
+ // init and render one frame, which will setup the Gears display lists
+ sharedDrawable.display();
+ }
+
+ private void releaseShared() {
+ Assert.assertNotNull(sharedDrawable);
+ sharedDrawable.destroy();
+ }
+
+ protected Frame runTestGL(Animator animator, int x, int y, boolean useShared) {
+ Frame frame = new Frame("Shared Gears AWT Test: "+x+"/"+y+" shared "+useShared);
+ Assert.assertNotNull(frame);
+
+ GLCanvas glCanvas = new GLCanvas(caps, useShared ? sharedDrawable.getContext() : null);
+ Assert.assertNotNull(glCanvas);
+ frame.add(glCanvas);
+ frame.setSize(width, height);
+ frame.setLocation(x, y);
+
+ Gears gears = new Gears();
+ if(useShared) {
+ gears.setGears(sharedGears.getGear1(), sharedGears.getGear2(), sharedGears.getGear3());
+ }
+ glCanvas.addGLEventListener(gears);
+
+ animator.add(glCanvas);
+
+ frame.setVisible(true);
+
+ return frame;
+ }
+
+ @Test
+ public void test01() throws InterruptedException {
+ initShared();
+ Animator animator = new Animator();
+ Frame f1 = runTestGL(animator, 0, 0, true);
+ Frame f2 = runTestGL(animator, width, 0, true);
+ Frame f3 = runTestGL(animator, 0, height, false);
+ animator.start();
+ while(animator.isAnimating() && animator.getDuration()<duration) {
+ Thread.sleep(100);
+ }
+ animator.stop();
+ f1.dispose();
+ f2.dispose();
+ f3.dispose();
+ releaseShared();
+ }
+
+ static long duration = 500; // ms
+
+ public static void main(String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ try {
+ duration = Integer.parseInt(args[i]);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ }
+ }
+ org.junit.runner.JUnitCore.main(TestSharedContextListAWT.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT.java
new file mode 100644
index 000000000..24280f244
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT.java
@@ -0,0 +1,133 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.acore;
+
+import com.jogamp.newt.opengl.GLWindow;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLDrawableFactory;
+import javax.media.opengl.GLPbuffer;
+import javax.media.opengl.GLProfile;
+import com.jogamp.opengl.util.Animator;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestSharedContextListNEWT extends UITestCase {
+ static GLProfile glp;
+ static GLCapabilities caps;
+ static int width, height;
+ GLPbuffer sharedDrawable;
+ Gears sharedGears;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ glp = GLProfile.getDefault();
+ Assert.assertNotNull(glp);
+ caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ width = 512;
+ height = 512;
+ }
+
+ private void initShared() {
+ sharedDrawable = GLDrawableFactory.getFactory(glp).createGLPbuffer(null, caps, null, width, height, null);
+ Assert.assertNotNull(sharedDrawable);
+ sharedGears = new Gears();
+ Assert.assertNotNull(sharedGears);
+ sharedDrawable.addGLEventListener(sharedGears);
+ // init and render one frame, which will setup the Gears display lists
+ sharedDrawable.display();
+ }
+
+ private void releaseShared() {
+ Assert.assertNotNull(sharedDrawable);
+ sharedDrawable.destroy();
+ }
+
+ protected GLWindow runTestGL(Animator animator, int x, int y, boolean useShared) {
+ GLWindow glWindow = GLWindow.create(caps);
+ Assert.assertNotNull(glWindow);
+ glWindow.setTitle("Shared Gears NEWT Test: "+x+"/"+y+" shared "+useShared);
+ if(useShared) {
+ glWindow.setSharedContext(sharedDrawable.getContext());
+ }
+
+ glWindow.setSize(width, height);
+ glWindow.setPosition(x, y);
+
+ Gears gears = new Gears();
+ if(useShared) {
+ gears.setGears(sharedGears.getGear1(), sharedGears.getGear2(), sharedGears.getGear3());
+ }
+ glWindow.addGLEventListener(gears);
+
+ animator.add(glWindow);
+
+ glWindow.setVisible(true);
+
+ return glWindow;
+ }
+
+ @Test
+ public void test01() throws InterruptedException {
+ initShared();
+ Animator animator = new Animator();
+ GLWindow f1 = runTestGL(animator, 0, 0, true);
+ GLWindow f2 = runTestGL(animator, width, 0, true);
+ GLWindow f3 = runTestGL(animator, 0, height, false);
+ animator.start();
+ while(animator.isAnimating() && animator.getDuration()<duration) {
+ Thread.sleep(100);
+ }
+ animator.stop();
+ f1.destroy();
+ f2.destroy();
+ f3.destroy();
+ releaseShared();
+ }
+
+ static long duration = 500; // ms
+
+ public static void main(String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ try {
+ duration = Integer.parseInt(args[i]);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ }
+ }
+ org.junit.runner.JUnitCore.main(TestSharedContextListNEWT.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT01GLn.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT01GLn.java
new file mode 100644
index 000000000..83561eb97
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT01GLn.java
@@ -0,0 +1,147 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.awt;
+
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.awt.GLCanvas;
+import com.jogamp.opengl.util.Animator;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+
+import java.awt.Frame;
+
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.Test;
+
+
+public class TestAWT01GLn extends UITestCase {
+ Frame frame=null;
+ GLCanvas glCanvas=null;
+
+ @BeforeClass
+ public static void startup() {
+ GLProfile.initSingleton(true);
+ System.out.println("GLProfile "+GLProfile.glAvailabilityToString());
+ }
+
+ @Before
+ public void init() {
+ frame = new Frame("Texture Test");
+ Assert.assertNotNull(frame);
+ }
+
+ @After
+ public void release() {
+ Assert.assertNotNull(frame);
+ Assert.assertNotNull(glCanvas);
+ try {
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.setVisible(false);
+ frame.remove(glCanvas);
+ frame.dispose();
+ }});
+ } catch (Throwable t) {
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+ frame=null;
+ glCanvas=null;
+ }
+
+ protected void runTestGL(GLCapabilities caps) throws InterruptedException {
+ glCanvas = new GLCanvas(caps);
+ Assert.assertNotNull(glCanvas);
+ glCanvas.addGLEventListener(new Gears());
+ frame.add(glCanvas);
+
+ // Revalidate size/layout.
+ // Always validate if component added/removed.
+ // Ensure 1st paint of GLCanvas will have a valid size, hence drawable gets created.
+ frame.setSize(512, 512);
+ frame.validate();
+
+ try {
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.setVisible(true);
+ }});
+ } catch (Throwable t) {
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+
+ glCanvas.display(); // one in process display
+
+ Animator animator = new Animator(glCanvas);
+ animator.start();
+
+ Thread.sleep(500); // 500 ms
+
+ animator.stop();
+ }
+
+ @Test
+ public void test01GLDefault() throws InterruptedException {
+ GLProfile glp = GLProfile.getDefault();
+ System.out.println("GLProfile Default: "+glp);
+ GLCapabilities caps = new GLCapabilities(glp);
+ runTestGL(caps);
+ }
+
+ @Test
+ public void test03GLMaxFixed() throws InterruptedException {
+ GLProfile maxFixed = GLProfile.getMaxFixedFunc();
+ System.out.println("GLProfile MaxFixed: "+maxFixed);
+ GLCapabilities caps = new GLCapabilities(maxFixed);
+ try {
+ runTestGL(caps);
+ } catch (Throwable t) {
+ // FIXME:
+ // Stop test and ignore if GL3bc and GL4bc
+ // currently this won't work on ATI!
+ if(maxFixed.equals(GLProfile.GL3bc) ||
+ maxFixed.equals(GLProfile.GL4bc)) {
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+ // else .. serious unexpected exception
+ }
+ }
+
+ public static void main(String args[]) {
+ org.junit.runner.JUnitCore.main(TestAWT01GLn.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT02WindowClosing.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT02WindowClosing.java
new file mode 100644
index 000000000..535f0e99e
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT02WindowClosing.java
@@ -0,0 +1,111 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.awt;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import javax.media.opengl.GLProfile;
+
+import java.awt.*;
+import java.awt.event.*;
+
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.Test;
+
+public class TestAWT02WindowClosing extends UITestCase {
+
+ static long durationPerTest = 200; // ms
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ }
+
+ @Test
+ public void test01WindowClosing() throws InterruptedException {
+ Frame frame = new Frame();
+ frame.setSize(500, 500);
+ ClosingWindowAdapter closingWindowAdapter = new ClosingWindowAdapter(frame);
+ frame.addWindowListener(closingWindowAdapter);
+ final Frame _frame = frame;
+ try {
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ _frame.setVisible(true);
+ }});
+ } catch (Throwable t) {
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+
+ Thread.sleep(durationPerTest);
+ if(!closingWindowAdapter.closingCalled) {
+ // programatically issue windowClosing
+ Toolkit tk = Toolkit.getDefaultToolkit();
+ EventQueue evtQ = tk.getSystemEventQueue();
+ evtQ.postEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
+ Thread.sleep(200);
+ }
+ Assert.assertEquals(true, closingWindowAdapter.closingCalled);
+ }
+
+ static class ClosingWindowAdapter extends WindowAdapter {
+ boolean closingCalled = false;
+ Frame frame;
+ public ClosingWindowAdapter(Frame frame) {
+ this.frame = frame;
+ }
+ public void windowClosing(WindowEvent ev) {
+ System.out.println("windowClosing() called ..");
+ closingCalled = true;
+ frame.dispose();
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ System.out.println("durationPerTest: "+durationPerTest);
+ org.junit.runner.JUnitCore.main(TestAWT02WindowClosing.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT03GLCanvasRecreate01.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT03GLCanvasRecreate01.java
new file mode 100644
index 000000000..2faf8fa66
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT03GLCanvasRecreate01.java
@@ -0,0 +1,183 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.awt;
+
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.awt.GLCanvas;
+import com.jogamp.opengl.util.Animator;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
+
+import java.awt.Frame;
+import java.awt.Label;
+
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.Test;
+
+
+public class TestAWT03GLCanvasRecreate01 extends UITestCase {
+ static long durationPerTest = 1000; // ms
+
+ Frame frame1=null;
+ Frame frame2=null;
+ GLCanvas glCanvas=null;
+ Label label = null;
+ Animator animator = null;
+
+ @BeforeClass
+ public static void startup() {
+ GLProfile.initSingleton(true);
+ System.out.println("GLProfile "+GLProfile.glAvailabilityToString());
+ }
+
+ @Before
+ public void init() {
+ glCanvas = new GLCanvas();
+ Assert.assertNotNull(glCanvas);
+ glCanvas.addGLEventListener(new Gears());
+
+ animator = new Animator(glCanvas);
+ animator.start();
+
+ label = new Label("No GLCanvas");
+
+ frame1 = new Frame("Frame 1");
+ Assert.assertNotNull(frame1);
+ frame1.add(label);
+ frame1.setSize(512, 512);
+ frame1.setLocation(0, 0);
+
+ frame2 = new Frame("Frame 2");
+ Assert.assertNotNull(frame2);
+ frame2.add(label);
+ frame2.setSize(512, 512);
+ frame2.setLocation(512, 0);
+ }
+
+ @After
+ public void release() {
+ Assert.assertNotNull(frame1);
+ Assert.assertNotNull(frame2);
+ Assert.assertNotNull(glCanvas);
+ try {
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ glCanvas.destroy();
+ frame1.dispose();
+ frame2.dispose();
+ }});
+ } catch (Throwable t) {
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+ frame1=null;
+ frame2=null;
+ glCanvas=null;
+
+ animator.stop();
+ animator=null;
+ }
+
+ private void addCanvas(final Frame frame) {
+ try {
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.remove(label);
+ frame.add(glCanvas);
+ frame.validate();
+ }});
+ } catch (Throwable t) {
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+ }
+
+ private void removeCanvas(final Frame frame) {
+ try {
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.remove(glCanvas);
+ frame.add(label);
+ frame.validate();
+ }});
+ } catch (Throwable t) {
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+ }
+
+ private void setVisible(final Frame frame, final boolean v) {
+ try {
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.setVisible(v);
+ }});
+ } catch (Throwable t) {
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+ }
+
+
+ @Test
+ public void testAddRemove3Times() throws InterruptedException {
+ setVisible(frame1, true);
+ setVisible(frame2, true);
+
+ addCanvas(frame1);
+ Thread.sleep(durationPerTest/4);
+
+ removeCanvas(frame1);
+ addCanvas(frame2);
+ Thread.sleep(durationPerTest/4);
+
+ removeCanvas(frame2);
+ addCanvas(frame1);
+ Thread.sleep(durationPerTest/4);
+
+ removeCanvas(frame1);
+ addCanvas(frame2);
+ Thread.sleep(durationPerTest/4);
+ }
+
+ public static void main(String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = MiscUtils.atoi(args[++i], (int)durationPerTest);
+ }
+ }
+ org.junit.runner.JUnitCore.main(TestAWT03GLCanvasRecreate01.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestSwingAWT01GLn.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestSwingAWT01GLn.java
new file mode 100644
index 000000000..8f642dfc9
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestSwingAWT01GLn.java
@@ -0,0 +1,159 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.awt;
+
+import java.lang.reflect.InvocationTargetException;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.awt.GLCanvas;
+import com.jogamp.opengl.util.Animator;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+import java.awt.Frame;
+import java.awt.Window;
+import javax.swing.JFrame;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assume.*;
+import static org.junit.Assert.*;
+import static javax.swing.SwingUtilities.*;
+
+/**
+ * Tests context creation + display on various kinds of Window implementations.
+ * @author Michael Bien
+ */
+public class TestSwingAWT01GLn extends UITestCase {
+ private Window[] windows;
+
+
+ @BeforeClass
+ public static void startup() {
+ GLProfile.initSingleton(true);
+ System.out.println("GLProfile "+GLProfile.glAvailabilityToString());
+ }
+
+ @Before
+ public void init() {
+ windows = new Window[]{
+ new Window(null),
+ new Frame("Frame GL test"),
+ new JFrame("JFrame GL test")
+ };
+ }
+
+ protected void runTestGL(final GLCapabilities caps) throws InterruptedException, InvocationTargetException {
+
+ for (final Window window : windows) {
+
+ System.out.println("testing with "+window.getClass().getName());
+
+ // final array as mutable container hack
+ final GLCanvas[] glCanvas = new GLCanvas[1];
+
+ Runnable test = new Runnable() {
+ public void run() {
+ glCanvas[0] = new GLCanvas(caps);
+ glCanvas[0].addGLEventListener(new Gears());
+ window.add(glCanvas[0]);
+
+ // Revalidate size/layout.
+ // Always validate if component added/removed.
+ // Ensure 1st paint of GLCanvas will have a valid size, hence drawable gets created.
+ window.setSize(512, 512);
+ window.validate();
+
+ window.setVisible(true);
+ glCanvas[0].display();
+ }
+ };
+
+ Runnable cleanup = new Runnable() {
+ public void run() {
+ System.out.println("cleaning up...");
+ window.setVisible(false);
+ try {
+ window.removeAll();
+ } catch (Throwable t) {
+ assumeNoException(t);
+ t.printStackTrace();
+ }
+ window.dispose();
+ }
+
+ };
+
+ // AWT / Swing on EDT..
+ invokeAndWait(test);
+
+ Animator animator = new Animator(glCanvas[0]);
+ animator.start();
+ Thread.sleep(1000);
+ animator.stop();
+
+ // AWT / Swing on EDT..
+ invokeAndWait(cleanup);
+ }
+ }
+
+ @Test
+ public void test01GLDefault() throws InterruptedException, InvocationTargetException {
+ GLProfile glp = GLProfile.getDefault();
+ System.out.println("GLProfile Default: "+glp);
+ GLCapabilities caps = new GLCapabilities(glp);
+ runTestGL(caps);
+ }
+
+ @Test
+ public void test03GLMaxFixed() throws InterruptedException, InvocationTargetException {
+ GLProfile maxFixed = GLProfile.getMaxFixedFunc();
+ System.out.println("GLProfile MaxFixed: "+maxFixed);
+ GLCapabilities caps = new GLCapabilities(maxFixed);
+ try {
+ runTestGL(caps);
+ } catch (Throwable t) {
+ // FIXME:
+ // Stop test and ignore if GL3bc and GL4bc
+ // currently this won't work on ATI!
+ if(maxFixed.getName().equals(GLProfile.GL3bc) ||
+ maxFixed.getName().equals(GLProfile.GL4bc)) {
+ t.printStackTrace();
+ assumeNoException(t);
+ }
+ // else .. serious unexpected exception
+ }
+ }
+
+ public static void main(String args[]) {
+ org.junit.runner.JUnitCore.main(TestSwingAWT01GLn.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleChooser01.java b/src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleChooser01.java
new file mode 100644
index 000000000..9653038d1
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleChooser01.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ *
+ * Sun gratefully acknowledges that this software was originally authored
+ * and developed by Kenneth Bradley Russell and Christopher John Kline.
+ */
+package com.jogamp.opengl.test.junit.jogl.caps;
+
+import javax.media.opengl.DefaultGLCapabilitiesChooser;
+import javax.media.opengl.GLCapabilitiesImmutable;
+
+class MultisampleChooser01 extends DefaultGLCapabilitiesChooser {
+
+ public int chooseCapabilities(GLCapabilitiesImmutable desired, GLCapabilitiesImmutable[] available, int windowSystemRecommendedChoice) {
+ boolean anyHaveSampleBuffers = false;
+ for (int i = 0; i < available.length; i++) {
+ GLCapabilitiesImmutable caps = available[i];
+ if (caps != null && caps.getSampleBuffers()) {
+ anyHaveSampleBuffers = true;
+ break;
+ }
+ }
+ int selection = super.chooseCapabilities(desired, available, windowSystemRecommendedChoice);
+ if (!anyHaveSampleBuffers) {
+ System.err.println("WARNING: antialiasing will be disabled because none of the available pixel formats had it to offer");
+ } else {
+ if (!available[selection].getSampleBuffers()) {
+ System.err.println("WARNING: antialiasing will be disabled because the DefaultGLCapabilitiesChooser didn't supply it");
+ }
+ }
+ return selection;
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleDemo01.java b/src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleDemo01.java
new file mode 100644
index 000000000..a9995d8e8
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleDemo01.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ *
+ * Sun gratefully acknowledges that this software was originally authored
+ * and developed by Kenneth Bradley Russell and Christopher John Kline.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.caps;
+
+import com.jogamp.opengl.impl.x11.glx.GLX;
+import com.jogamp.opengl.impl.x11.glx.X11GLXGraphicsConfiguration;
+import javax.media.nativewindow.AbstractGraphicsConfiguration;
+import javax.media.nativewindow.NativeWindowFactory;
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2;
+import javax.media.opengl.GL2ES1;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLPipelineFactory;
+
+class MultisampleDemo01 implements GLEventListener {
+
+ static boolean glDebug = false;
+ static boolean glTrace = false;
+
+ boolean multisample;
+
+ public MultisampleDemo01(boolean multisample) {
+ this.multisample = multisample;
+ }
+
+ public void init(GLAutoDrawable drawable) {
+ AbstractGraphicsConfiguration config = drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration();
+ System.err.println();
+ System.err.println("Info: " + config);
+ System.err.println();
+ if (NativeWindowFactory.TYPE_X11.equals(NativeWindowFactory.getNativeWindowType(false))) {
+ X11GLXGraphicsConfiguration x11config = (X11GLXGraphicsConfiguration) config;
+ long display = drawable.getNativeSurface().getDisplayHandle();
+ int[] foo = new int[1];
+ GLX.glXGetFBConfigAttrib(display, x11config.getFBConfig(), GLX.GLX_SAMPLES, foo, 0);
+ System.out.println("GLX_SAMPLES " + foo[0]);
+ GLX.glXGetFBConfigAttrib(display, x11config.getFBConfig(), GLX.GLX_SAMPLE_BUFFERS, foo, 0);
+ System.out.println("GLX_SAMPLE_BUFFERS " + foo[0]);
+ }
+ GL _gl = drawable.getGL();
+ if (glDebug) {
+ try {
+ // Debug ..
+ _gl = _gl.getContext().setGL(GLPipelineFactory.create("javax.media.opengl.Debug", GL2.class, _gl, null));
+ if (glTrace) {
+ // Trace ..
+ _gl = _gl.getContext().setGL(GLPipelineFactory.create("javax.media.opengl.Trace", GL2.class, _gl, new Object[]{System.err}));
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ GL2 gl = _gl.getGL2();
+ if (multisample) {
+ gl.glEnable(GL.GL_MULTISAMPLE);
+ }
+ gl.glClearColor(0, 0, 0, 0);
+ // gl.glEnable(GL.GL_DEPTH_TEST);
+ // gl.glDepthFunc(GL.GL_LESS);
+ gl.glMatrixMode(GL2ES1.GL_MODELVIEW);
+ gl.glLoadIdentity();
+ gl.glMatrixMode(GL2ES1.GL_PROJECTION);
+ gl.glLoadIdentity();
+ gl.glOrtho(-1, 1, -1, 1, -1, 1);
+ if (multisample) {
+ gl.glDisable(GL.GL_MULTISAMPLE);
+ }
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ GL2 gl = drawable.getGL().getGL2();
+ if (multisample) {
+ gl.glEnable(GL.GL_MULTISAMPLE);
+ }
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+ int numSteps = 20;
+ double increment = Math.PI / numSteps;
+ double radius = 1;
+ gl.glBegin(GL.GL_LINES);
+ for (int i = numSteps - 1; i >= 0; i--) {
+ gl.glVertex3d(radius * Math.cos(i * increment), radius * Math.sin(i * increment), 0);
+ gl.glVertex3d(-1.0 * radius * Math.cos(i * increment), -1.0 * radius * Math.sin(i * increment), 0);
+ }
+ gl.glEnd();
+ if (multisample) {
+ gl.glDisable(GL.GL_MULTISAMPLE);
+ }
+ }
+
+ // Unused routines
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ }
+
+ public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestMultisampleAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestMultisampleAWT.java
new file mode 100755
index 000000000..53047611d
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestMultisampleAWT.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ *
+ * Sun gratefully acknowledges that this software was originally authored
+ * and developed by Kenneth Bradley Russell and Christopher John Kline.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.caps;
+
+import com.jogamp.opengl.test.junit.util.MiscUtils;
+import java.awt.*;
+import javax.media.opengl.*;
+import javax.media.opengl.awt.GLCanvas;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import javax.media.nativewindow.AbstractGraphicsDevice;
+import javax.media.nativewindow.AbstractGraphicsScreen;
+import javax.media.nativewindow.GraphicsConfigurationFactory;
+import javax.media.nativewindow.awt.AWTGraphicsConfiguration;
+import javax.media.nativewindow.awt.AWTGraphicsDevice;
+import javax.media.nativewindow.awt.AWTGraphicsScreen;
+import org.junit.Test;
+
+
+public class TestMultisampleAWT extends UITestCase {
+ static long durationPerTest = 500; // ms
+ private GLCanvas canvas;
+
+ public static void main(String[] args) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = MiscUtils.atoi(args[++i], 500);
+ }
+ }
+ System.out.println("durationPerTest: "+durationPerTest);
+ String tstname = TestMultisampleAWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+ @Test
+ public void testMultiSampleAA4() throws InterruptedException {
+ testMultiSampleAAImpl(4);
+ }
+
+ // @Test
+ public void testMultiSampleNone() throws InterruptedException {
+ testMultiSampleAAImpl(0);
+ }
+
+ private void testMultiSampleAAImpl(int samples) throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(null);
+ GLCapabilitiesChooser chooser = new MultisampleChooser01();
+
+ if(samples>0) {
+ caps.setSampleBuffers(true);
+ caps.setNumSamples(samples);
+ }
+ // turns out we need to have alpha,
+ // otherwise no AA will be visible.
+ caps.setAlphaBits(1);
+
+ /**
+ * whatever I tried here (passing and preconfig GraphicsConfiguration)
+ * either it just didn't picked up .. or the context couldn't be made current.
+ *
+ GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
+ GraphicsConfiguration gc = AWTGraphicsConfiguration.getAWTGraphicsConfiguration(caps, gd);
+
+ AbstractGraphicsScreen aScreen = AWTGraphicsScreen.createScreenDevice(gd, AbstractGraphicsDevice.DEFAULT_UNIT);
+ AWTGraphicsConfiguration config = (AWTGraphicsConfiguration)
+ GraphicsConfigurationFactory.getFactory(AWTGraphicsDevice.class).chooseGraphicsConfiguration(caps, caps,
+ chooser, aScreen);
+ canvas = new GLCanvas(caps, chooser, null, gd, config.getGraphicsConfiguration(), config); */
+ canvas = new GLCanvas(caps, chooser, null, null);
+ canvas.addGLEventListener(new MultisampleDemo01(samples>0?true:false));
+
+ Frame frame = new Frame("Multi Samples "+samples);
+ frame.setLayout(new BorderLayout());
+ canvas.setSize(512, 512);
+ frame.add(canvas, BorderLayout.CENTER);
+ frame.pack();
+ frame.setVisible(true);
+ frame.setLocation(0, 0);
+ canvas.requestFocus();
+
+ Thread.sleep(durationPerTest);
+
+ frame.dispose();
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestMultisampleNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestMultisampleNEWT.java
new file mode 100755
index 000000000..8285a6699
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestMultisampleNEWT.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ *
+ * Sun gratefully acknowledges that this software was originally authored
+ * and developed by Kenneth Bradley Russell and Christopher John Kline.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.caps;
+
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
+import javax.media.opengl.*;
+import org.junit.Test;
+
+public class TestMultisampleNEWT {
+ static long durationPerTest = 500; // ms
+ private GLWindow window;
+
+ public static void main(String[] args) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = MiscUtils.atoi(args[++i], 500);
+ }
+ }
+ System.out.println("durationPerTest: "+durationPerTest);
+ String tstname = TestMultisampleNEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+ @Test
+ public void testMultiSampleAA4() throws InterruptedException {
+ testMultiSampleAAImpl(4);
+ }
+
+ // @Test
+ public void testMultiSampleNone() throws InterruptedException {
+ testMultiSampleAAImpl(0);
+ }
+
+ private void testMultiSampleAAImpl(int samples) throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(null);
+ GLCapabilitiesChooser chooser = new MultisampleChooser01();
+
+ if(samples>0) {
+ caps.setSampleBuffers(true);
+ caps.setNumSamples(4);
+ }
+ // turns out we need to have alpha,
+ // otherwise no AA will be visible.
+ caps.setAlphaBits(1);
+
+ window = GLWindow.create(caps);
+ window.setCapabilitiesChooser(chooser);
+ window.addGLEventListener(new MultisampleDemo01(samples>0?true:false));
+ window.setSize(512, 512);
+ window.setVisible(true);
+ window.setPosition(0, 0);
+ window.requestFocus();
+
+ GLCapabilitiesImmutable capsChosen0 = window.getChosenGLCapabilities();
+
+ Thread.sleep(durationPerTest);
+
+ window.destroy();
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquare.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquare.java
new file mode 100644
index 000000000..eaf697a10
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquare.java
@@ -0,0 +1,169 @@
+package com.jogamp.opengl.test.junit.jogl.demos.es1;
+
+import com.jogamp.common.nio.Buffers;
+import java.nio.*;
+import java.util.*;
+import javax.media.opengl.*;
+import javax.media.opengl.glu.*;
+import javax.media.nativewindow.*;
+
+import com.jogamp.opengl.util.*;
+import com.jogamp.opengl.util.glsl.fixedfunc.*;
+
+public class RedSquare implements GLEventListener {
+
+ public static boolean glDebugEmu = false;
+ public static boolean glDebug = false ;
+ public static boolean glTrace = false ;
+ public static boolean oneThread = false;
+ public static boolean useAnimator = false;
+ public static int swapInterval = -1;
+
+ boolean debug = false;
+ long startTime = 0;
+ long curTime = 0;
+
+ GLU glu = null;
+
+ public RedSquare() {
+ this(false);
+ }
+
+ public RedSquare(boolean debug) {
+ this.debug = debug;
+ }
+
+ // FIXME: we must add storage of the pointers in the GL state to
+ // the GLImpl classes. The need for this can be seen by making
+ // these variables method local instead of instance members. The
+ // square will disappear after a second or so due to garbage
+ // collection. On desktop OpenGL this implies a stack of
+ // references due to the existence of glPush/PopClientAttrib. On
+ // OpenGL ES 1/2 it can simply be one set of references.
+ private FloatBuffer colors;
+ private FloatBuffer vertices;
+
+ public void init(GLAutoDrawable drawable) {
+ System.out.println("RedSquare: Init");
+ GL _gl = drawable.getGL();
+
+ if(glDebugEmu) {
+ try {
+ // Debug ..
+ _gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", GL2ES2.class, _gl, null) );
+
+ if(glTrace) {
+ // Trace ..
+ _gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", GL2ES2.class, _gl, new Object[] { System.err } ) );
+ }
+ } catch (Exception e) {e.printStackTrace();}
+ glDebug = false;
+ glTrace = false;
+ }
+
+ GL2ES1 gl = FixedFuncUtil.getFixedFuncImpl(_gl);
+ if(swapInterval>=0) {
+ gl.setSwapInterval(swapInterval);
+ }
+
+ if(glDebug) {
+ try {
+ // Debug ..
+ gl = (GL2ES1) gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", GL2ES1.class, gl, null) );
+ } catch (Exception e) {e.printStackTrace();}
+ }
+
+ if(glTrace) {
+ try {
+ // Trace ..
+ gl = (GL2ES1) gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", GL2ES1.class, gl, new Object[] { System.err } ) );
+ } catch (Exception e) {e.printStackTrace();}
+ }
+
+ glu = GLU.createGLU(gl);
+
+ if(debug) {
+ System.err.println(Thread.currentThread()+" Entering initialization");
+ System.err.println(Thread.currentThread()+" GL Profile: "+gl.getGLProfile());
+ System.err.println(Thread.currentThread()+" GL:" + gl);
+ System.err.println(Thread.currentThread()+" GL_VERSION=" + gl.glGetString(gl.GL_VERSION));
+ System.err.println(Thread.currentThread()+" GL_EXTENSIONS:");
+ System.err.println(Thread.currentThread()+" " + gl.glGetString(gl.GL_EXTENSIONS));
+ System.err.println(Thread.currentThread()+" swapInterval: " + swapInterval + " (GL: "+gl.getSwapInterval()+")");
+ System.err.println(Thread.currentThread()+" GLU: " + glu);
+ }
+
+ // Allocate vertex arrays
+ colors = Buffers.newDirectFloatBuffer(16);
+ vertices = Buffers.newDirectFloatBuffer(12);
+ // Fill them up
+ colors.put( 0, 1); colors.put( 1, 0); colors.put( 2, 0); colors.put( 3, 1);
+ colors.put( 4, 0); colors.put( 5, 0); colors.put( 6, 1); colors.put( 7, 1);
+ colors.put( 8, 1); colors.put( 9, 0); colors.put(10, 0); colors.put(11, 1);
+ colors.put(12, 1); colors.put(13, 0); colors.put(14, 0); colors.put(15, 1);
+ vertices.put(0, -2); vertices.put( 1, 2); vertices.put( 2, 0);
+ vertices.put(3, 2); vertices.put( 4, 2); vertices.put( 5, 0);
+ vertices.put(6, -2); vertices.put( 7, -2); vertices.put( 8, 0);
+ vertices.put(9, 2); vertices.put(10, -2); vertices.put(11, 0);
+
+ gl.glEnableClientState(gl.GL_VERTEX_ARRAY);
+ gl.glEnableClientState(gl.GL_COLOR_ARRAY);
+ gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertices);
+ gl.glColorPointer(4, GL.GL_FLOAT, 0, colors);
+
+ // OpenGL Render Settings
+ gl.glClearColor(0, 0, 0, 1);
+ gl.glEnable(GL.GL_DEPTH_TEST);
+
+ startTime = System.currentTimeMillis();
+ curTime = startTime;
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ System.out.println("RedSquare: Reshape");
+ GL2ES1 gl = drawable.getGL().getGL2ES1();
+ // Set location in front of camera
+ gl.glMatrixMode(gl.GL_PROJECTION);
+ gl.glLoadIdentity();
+ glu.gluPerspective(45.0f, (float)width / (float)height, 1.0f, 100.0f);
+ //gl.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f);
+ //glu.gluLookAt(0, 0, -20, 0, 0, 0, 0, 1, 0);
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ curTime = System.currentTimeMillis();
+ GL2ES1 gl = drawable.getGL().getGL2ES1();
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+
+ // One rotation every four seconds
+ gl.glMatrixMode(gl.GL_MODELVIEW);
+ gl.glLoadIdentity();
+ gl.glTranslatef(0, 0, -10);
+ float ang = ((float) (curTime - startTime) * 360.0f) / 4000.0f;
+ gl.glRotatef(ang, 0, 0, 1);
+ gl.glRotatef(ang, 0, 1, 0);
+
+
+ // Draw a square
+ gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4);
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ System.out.println("RedSquare: Dispose");
+ GL2ES1 gl = drawable.getGL().getGL2ES1();
+ if(debug) {
+ System.out.println(Thread.currentThread()+" RedSquare.dispose: "+gl.getContext());
+ }
+ gl.glDisableClientState(gl.GL_VERTEX_ARRAY);
+ gl.glDisableClientState(gl.GL_COLOR_ARRAY);
+ glu.destroy();
+ glu = null;
+ colors.clear();
+ colors = null;
+ vertices.clear();
+ vertices = null;
+ if(debug) {
+ System.out.println(Thread.currentThread()+" RedSquare.dispose: FIN");
+ }
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquare0.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquare0.java
new file mode 100644
index 000000000..f062a7375
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquare0.java
@@ -0,0 +1,198 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.opengl.test.junit.jogl.demos.es2;
+
+import com.jogamp.common.nio.Buffers;
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.GLArrayDataWrapper;
+import com.jogamp.opengl.util.PMVMatrix;
+import com.jogamp.opengl.test.junit.jogl.demos.es2.shader.RedSquareShader;
+import com.jogamp.opengl.test.junit.util.GLSLSimpleProgram;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.nio.FloatBuffer;
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLContext;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLUniformData;
+import org.junit.Assert;
+
+public class RedSquare0 implements GLEventListener {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintStream pbaos = new PrintStream(baos);
+ GLSLSimpleProgram myShader;
+ PMVMatrix pmvMatrix;
+ int mgl_PMVMatrix;
+ GLUniformData pmvMatrixUniform;
+ int mgl_Vertex;
+ int mgl_Color;
+ long t0;
+
+ public void init(GLAutoDrawable glad) {
+ GLContext context = glad.getContext();
+ context.makeCurrent();
+ GL2ES2 gl = context.getGL().getGL2ES2();
+ myShader = GLSLSimpleProgram.create(gl, RedSquareShader.VERTEX_SHADER_TEXT, RedSquareShader.FRAGMENT_SHADER_TEXT, true);
+ gl.glUseProgram(myShader.getShaderProgram());
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ // setup mgl_PMVMatrix
+ pmvMatrix = new PMVMatrix();
+ pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION);
+ pmvMatrix.glLoadIdentity();
+ pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW);
+ pmvMatrix.glLoadIdentity();
+ mgl_PMVMatrix = gl.glGetUniformLocation(myShader.getShaderProgram(), "mgl_PMVMatrix");
+ Assert.assertTrue(0 <= mgl_PMVMatrix);
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf());
+ pmvMatrixUniform.setLocation(mgl_PMVMatrix);
+ gl.glUniform(pmvMatrixUniform);
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ // Allocate Vertex Array
+ int components = 3;
+ int numElements = 4;
+ mgl_Vertex = gl.glGetAttribLocation(myShader.getShaderProgram(), "mgl_Vertex");
+ Assert.assertTrue(0 <= mgl_Vertex);
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ FloatBuffer buffer = Buffers.newDirectFloatBuffer(numElements * components);
+ GLArrayDataWrapper vertices = GLArrayDataWrapper.createGLSL(gl, "mgl_Vertex", 3, gl.GL_FLOAT, false, 0, buffer, -1, 0);
+ {
+ // Fill them up
+ FloatBuffer verticeb = (FloatBuffer) vertices.getBuffer();
+ verticeb.put(-2);
+ verticeb.put(2);
+ verticeb.put(0);
+ verticeb.put(2);
+ verticeb.put(2);
+ verticeb.put(0);
+ verticeb.put(-2);
+ verticeb.put(-2);
+ verticeb.put(0);
+ verticeb.put(2);
+ verticeb.put(-2);
+ verticeb.put(0);
+ }
+ buffer.flip();
+ vertices.setLocation(mgl_Vertex);
+ gl.glEnableVertexAttribArray(mgl_Vertex);
+ gl.glVertexAttribPointer(vertices);
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ // Allocate Color Array
+ components = 4;
+ numElements = 4;
+ mgl_Color = gl.glGetAttribLocation(myShader.getShaderProgram(), "mgl_Color");
+ Assert.assertTrue(0 <= mgl_Color);
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ buffer = Buffers.newDirectFloatBuffer(numElements * components);
+ GLArrayDataWrapper colors = GLArrayDataWrapper.createGLSL(gl, "mgl_Color", 4, gl.GL_FLOAT, false, 0, buffer, -1, 0);
+ {
+ // Fill them up
+ FloatBuffer colorb = (FloatBuffer) colors.getBuffer();
+ colorb.put(1);
+ colorb.put(0);
+ colorb.put(0);
+ colorb.put(1);
+ colorb.put(0);
+ colorb.put(0);
+ colorb.put(1);
+ colorb.put(1);
+ colorb.put(1);
+ colorb.put(0);
+ colorb.put(0);
+ colorb.put(1);
+ colorb.put(1);
+ colorb.put(0);
+ colorb.put(0);
+ colorb.put(1);
+ }
+ buffer.flip();
+ colors.setLocation(mgl_Color);
+ gl.glEnableVertexAttribArray(mgl_Color);
+ gl.glVertexAttribPointer(colors);
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ // OpenGL Render Settings
+ gl.glClearColor(0, 0, 0, 1);
+ gl.glEnable(GL2ES2.GL_DEPTH_TEST);
+ gl.glUseProgram(0);
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+
+ t0 = System.currentTimeMillis();
+ }
+
+ public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) {
+ GL2ES2 gl = glad.getGL().getGL2ES2();
+ gl.glUseProgram(myShader.getShaderProgram());
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ // Set location in front of camera
+ pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION);
+ pmvMatrix.glLoadIdentity();
+ pmvMatrix.gluPerspective(45.0F, (float) width / (float) height, 1.0F, 100.0F);
+ //pmvMatrix.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f);
+ gl.glUniform(pmvMatrixUniform);
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ gl.glUseProgram(0);
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ }
+
+ public void display(GLAutoDrawable glad) {
+ long t1 = System.currentTimeMillis();
+
+ GL2ES2 gl = glad.getGL().getGL2ES2();
+ gl.glUseProgram(myShader.getShaderProgram());
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ // One rotation every four seconds
+ pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW);
+ pmvMatrix.glLoadIdentity();
+ pmvMatrix.glTranslatef(0, 0, -10);
+ float ang = ((float) (t1 - t0) * 360.0F) / 4000.0F;
+ pmvMatrix.glRotatef(ang, 0, 0, 1);
+ pmvMatrix.glRotatef(ang, 0, 1, 0);
+ gl.glUniform(pmvMatrixUniform);
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ // Draw a square
+ gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4);
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ gl.glUseProgram(0);
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ }
+
+ public void dispose(GLAutoDrawable glad) {
+ GL2ES2 gl = glad.getGL().getGL2ES2();
+ gl.glDisableVertexAttribArray(mgl_Vertex);
+ gl.glDisableVertexAttribArray(mgl_Color);
+ myShader.release(gl);
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ pmvMatrix.destroy();
+ pmvMatrix = null;
+ System.err.println("dispose done");
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader.java
new file mode 100644
index 000000000..3ef62df31
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/RedSquareShader.java
@@ -0,0 +1,68 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.demos.es2.shader;
+
+public class RedSquareShader {
+ public static String VERTEX_SHADER_TEXT =
+ " #ifdef GL_ES\n" +
+ " #define MEDIUMP mediump\n" +
+ " #define HIGHP highp\n" +
+ "#else\n" +
+ " #define MEDIUMP\n" +
+ " #define HIGHP\n" +
+ "#endif\n" +
+ "\n" +
+ "uniform MEDIUMP mat4 mgl_PMVMatrix[2];\n" +
+ "attribute HIGHP vec4 mgl_Vertex;\n" +
+ "attribute HIGHP vec4 mgl_Color;\n" +
+ "varying HIGHP vec4 frontColor;\n" +
+ "\n" +
+ "void main(void)\n" +
+ "{\n" +
+ " frontColor=mgl_Color;\n" +
+ " gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex;\n" +
+ "}\n" ;
+
+ public static String FRAGMENT_SHADER_TEXT =
+ "#ifdef GL_ES\n" +
+ " #define MEDIUMP mediump\n" +
+ " #define HIGHP highp\n" +
+ "#else\n" +
+ " #define MEDIUMP\n" +
+ " #define HIGHP\n" +
+ "#endif\n" +
+ "\n" +
+ "varying HIGHP vec4 frontColor;\n" +
+ "\n" +
+ "void main (void)\n" +
+ "{\n" +
+ " gl_FragColor = frontColor;\n" +
+ "}\n" ;
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/Gears.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/Gears.java
new file mode 100644
index 000000000..dd28b4e40
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/Gears.java
@@ -0,0 +1,353 @@
+
+package com.jogamp.opengl.test.junit.jogl.demos.gl2.gears;
+
+import javax.media.opengl.*;
+
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.event.awt.*;
+import com.jogamp.newt.Window;
+
+/**
+ * Gears.java <BR>
+ * author: Brian Paul (converted to Java by Ron Cemer and Sven Gothel) <P>
+ *
+ * This version is equal to Brian Paul's version 1.2 1999/10/21
+ */
+
+public class Gears implements GLEventListener {
+ private float view_rotx = 20.0f, view_roty = 30.0f, view_rotz = 0.0f;
+ private int gear1=0, gear2=0, gear3=0;
+ private float angle = 0.0f;
+ private int swapInterval;
+
+ private boolean mouseRButtonDown = false;
+ private int prevMouseX, prevMouseY;
+
+ public Gears(int swapInterval) {
+ this.swapInterval = swapInterval;
+ }
+
+ public Gears() {
+ this.swapInterval = 1;
+ }
+
+ public void setGears(int g1, int g2, int g3) {
+ gear1 = g1;
+ gear2 = g2;
+ gear3 = g3;
+ }
+
+ /**
+ * @return display list gear1
+ */
+ public int getGear1() { return gear1; }
+
+ /**
+ * @return display list gear2
+ */
+ public int getGear2() { return gear2; }
+
+ /**
+ * @return display list gear3
+ */
+ public int getGear3() { return gear3; }
+
+ public void init(GLAutoDrawable drawable) {
+ System.err.println("Gears: Init");
+ // Use debug pipeline
+ // drawable.setGL(new DebugGL(drawable.getGL()));
+
+ GL2 gl = drawable.getGL().getGL2();
+
+ float pos[] = { 5.0f, 5.0f, 10.0f, 0.0f };
+ float red[] = { 0.8f, 0.1f, 0.0f, 0.7f };
+ float green[] = { 0.0f, 0.8f, 0.2f, 0.7f };
+ float blue[] = { 0.2f, 0.2f, 1.0f, 0.7f };
+
+ gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, pos, 0);
+ gl.glEnable(GL2.GL_CULL_FACE);
+ gl.glEnable(GL2.GL_LIGHTING);
+ gl.glEnable(GL2.GL_LIGHT0);
+ gl.glEnable(GL2.GL_DEPTH_TEST);
+
+ /* make the gears */
+ if(0>=gear1) {
+ gear1 = gl.glGenLists(1);
+ gl.glNewList(gear1, GL2.GL_COMPILE);
+ gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, red, 0);
+ gear(gl, 1.0f, 4.0f, 1.0f, 20, 0.7f);
+ gl.glEndList();
+ System.err.println("gear1 list created: "+gear1);
+ } else {
+ System.err.println("gear1 list reused: "+gear1);
+ }
+
+ if(0>=gear2) {
+ gear2 = gl.glGenLists(1);
+ gl.glNewList(gear2, GL2.GL_COMPILE);
+ gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, green, 0);
+ gear(gl, 0.5f, 2.0f, 2.0f, 10, 0.7f);
+ gl.glEndList();
+ System.err.println("gear2 list created: "+gear2);
+ } else {
+ System.err.println("gear2 list reused: "+gear2);
+ }
+
+ if(0>=gear3) {
+ gear3 = gl.glGenLists(1);
+ gl.glNewList(gear3, GL2.GL_COMPILE);
+ gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, blue, 0);
+ gear(gl, 1.3f, 2.0f, 0.5f, 10, 0.7f);
+ gl.glEndList();
+ System.err.println("gear3 list created: "+gear3);
+ } else {
+ System.err.println("gear3 list reused: "+gear3);
+ }
+
+ gl.glEnable(GL2.GL_NORMALIZE);
+
+ // MouseListener gearsMouse = new TraceMouseAdapter(new GearsMouseAdapter());
+ MouseListener gearsMouse = new GearsMouseAdapter();
+
+ if (drawable instanceof Window) {
+ Window window = (Window) drawable;
+ window.addMouseListener(gearsMouse);
+ } else if (GLProfile.isAWTAvailable() && drawable instanceof java.awt.Component) {
+ java.awt.Component comp = (java.awt.Component) drawable;
+ new AWTMouseAdapter(gearsMouse).addTo(comp);
+ }
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ System.err.println("Gears: Reshape "+x+"/"+y+" "+width+"x"+height);
+ GL2 gl = drawable.getGL().getGL2();
+
+ gl.setSwapInterval(swapInterval);
+
+ float h = (float)height / (float)width;
+
+ gl.glMatrixMode(GL2.GL_PROJECTION);
+
+ gl.glLoadIdentity();
+ gl.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
+ gl.glMatrixMode(GL2.GL_MODELVIEW);
+ gl.glLoadIdentity();
+ gl.glTranslatef(0.0f, 0.0f, -40.0f);
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ System.err.println("Gears: Dispose");
+ setGears(0, 0, 0);
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ // Turn the gears' teeth
+ angle += 2.0f;
+
+ // Get the GL corresponding to the drawable we are animating
+ GL2 gl = drawable.getGL().getGL2();
+
+ gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+
+ // Special handling for the case where the GLJPanel is translucent
+ // and wants to be composited with other Java 2D content
+ if (GLProfile.isAWTAvailable() &&
+ (drawable instanceof javax.media.opengl.awt.GLJPanel) &&
+ !((javax.media.opengl.awt.GLJPanel) drawable).isOpaque() &&
+ ((javax.media.opengl.awt.GLJPanel) drawable).shouldPreserveColorBufferIfTranslucent()) {
+ gl.glClear(GL2.GL_DEPTH_BUFFER_BIT);
+ } else {
+ gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
+ }
+
+ // Rotate the entire assembly of gears based on how the user
+ // dragged the mouse around
+ gl.glPushMatrix();
+ gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f);
+ gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
+ gl.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);
+
+ // Place the first gear and call its display list
+ gl.glPushMatrix();
+ gl.glTranslatef(-3.0f, -2.0f, 0.0f);
+ gl.glRotatef(angle, 0.0f, 0.0f, 1.0f);
+ gl.glCallList(gear1);
+ gl.glPopMatrix();
+
+ // Place the second gear and call its display list
+ gl.glPushMatrix();
+ gl.glTranslatef(3.1f, -2.0f, 0.0f);
+ gl.glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f);
+ gl.glCallList(gear2);
+ gl.glPopMatrix();
+
+ // Place the third gear and call its display list
+ gl.glPushMatrix();
+ gl.glTranslatef(-3.1f, 4.2f, 0.0f);
+ gl.glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f);
+ gl.glCallList(gear3);
+ gl.glPopMatrix();
+
+ // Remember that every push needs a pop; this one is paired with
+ // rotating the entire gear assembly
+ gl.glPopMatrix();
+ }
+
+ public static void gear(GL2 gl,
+ float inner_radius,
+ float outer_radius,
+ float width,
+ int teeth,
+ float tooth_depth)
+ {
+ int i;
+ float r0, r1, r2;
+ float angle, da;
+ float u, v, len;
+
+ r0 = inner_radius;
+ r1 = outer_radius - tooth_depth / 2.0f;
+ r2 = outer_radius + tooth_depth / 2.0f;
+
+ da = 2.0f * (float) Math.PI / teeth / 4.0f;
+
+ gl.glShadeModel(GL2.GL_FLAT);
+
+ gl.glNormal3f(0.0f, 0.0f, 1.0f);
+
+ /* draw front face */
+ gl.glBegin(GL2.GL_QUAD_STRIP);
+ for (i = 0; i <= teeth; i++)
+ {
+ angle = i * 2.0f * (float) Math.PI / teeth;
+ gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f);
+ gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f);
+ if(i < teeth)
+ {
+ gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f);
+ gl.glVertex3f(r1 * (float)Math.cos(angle + 3.0f * da), r1 * (float)Math.sin(angle + 3.0f * da), width * 0.5f);
+ }
+ }
+ gl.glEnd();
+
+ /* draw front sides of teeth */
+ gl.glBegin(GL2.GL_QUADS);
+ for (i = 0; i < teeth; i++)
+ {
+ angle = i * 2.0f * (float) Math.PI / teeth;
+ gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f);
+ gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), width * 0.5f);
+ gl.glVertex3f(r2 * (float)Math.cos(angle + 2.0f * da), r2 * (float)Math.sin(angle + 2.0f * da), width * 0.5f);
+ gl.glVertex3f(r1 * (float)Math.cos(angle + 3.0f * da), r1 * (float)Math.sin(angle + 3.0f * da), width * 0.5f);
+ }
+ gl.glEnd();
+
+ /* draw back face */
+ gl.glBegin(GL2.GL_QUAD_STRIP);
+ for (i = 0; i <= teeth; i++)
+ {
+ angle = i * 2.0f * (float) Math.PI / teeth;
+ gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f);
+ gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f);
+ gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f);
+ gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f);
+ }
+ gl.glEnd();
+
+ /* draw back sides of teeth */
+ gl.glBegin(GL2.GL_QUADS);
+ for (i = 0; i < teeth; i++)
+ {
+ angle = i * 2.0f * (float) Math.PI / teeth;
+ gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f);
+ gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), -width * 0.5f);
+ gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), -width * 0.5f);
+ gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f);
+ }
+ gl.glEnd();
+
+ /* draw outward faces of teeth */
+ gl.glBegin(GL2.GL_QUAD_STRIP);
+ for (i = 0; i < teeth; i++)
+ {
+ angle = i * 2.0f * (float) Math.PI / teeth;
+ gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f);
+ gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f);
+ u = r2 * (float)Math.cos(angle + da) - r1 * (float)Math.cos(angle);
+ v = r2 * (float)Math.sin(angle + da) - r1 * (float)Math.sin(angle);
+ len = (float)Math.sqrt(u * u + v * v);
+ u /= len;
+ v /= len;
+ gl.glNormal3f(v, -u, 0.0f);
+ gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), width * 0.5f);
+ gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), -width * 0.5f);
+ gl.glNormal3f((float)Math.cos(angle), (float)Math.sin(angle), 0.0f);
+ gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), width * 0.5f);
+ gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), -width * 0.5f);
+ u = r1 * (float)Math.cos(angle + 3 * da) - r2 * (float)Math.cos(angle + 2 * da);
+ v = r1 * (float)Math.sin(angle + 3 * da) - r2 * (float)Math.sin(angle + 2 * da);
+ gl.glNormal3f(v, -u, 0.0f);
+ gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), width * 0.5f);
+ gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f);
+ gl.glNormal3f((float)Math.cos(angle), (float)Math.sin(angle), 0.0f);
+ }
+ gl.glVertex3f(r1 * (float)Math.cos(0), r1 * (float)Math.sin(0), width * 0.5f);
+ gl.glVertex3f(r1 * (float)Math.cos(0), r1 * (float)Math.sin(0), -width * 0.5f);
+ gl.glEnd();
+
+ gl.glShadeModel(GL2.GL_SMOOTH);
+
+ /* draw inside radius cylinder */
+ gl.glBegin(GL2.GL_QUAD_STRIP);
+ for (i = 0; i <= teeth; i++)
+ {
+ angle = i * 2.0f * (float) Math.PI / teeth;
+ gl.glNormal3f(-(float)Math.cos(angle), -(float)Math.sin(angle), 0.0f);
+ gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f);
+ gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f);
+ }
+ gl.glEnd();
+ }
+
+ class GearsMouseAdapter extends MouseAdapter {
+ public void mousePressed(MouseEvent e) {
+ prevMouseX = e.getX();
+ prevMouseY = e.getY();
+ if ((e.getModifiers() & e.BUTTON3_MASK) != 0) {
+ mouseRButtonDown = true;
+ }
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ if ((e.getModifiers() & e.BUTTON3_MASK) != 0) {
+ mouseRButtonDown = false;
+ }
+ }
+
+ public void mouseDragged(MouseEvent e) {
+ int x = e.getX();
+ int y = e.getY();
+ int width=0, height=0;
+ Object source = e.getSource();
+ if(source instanceof Window) {
+ Window window = (Window) source;
+ width=window.getWidth();
+ height=window.getHeight();
+ } else if (GLProfile.isAWTAvailable() && source instanceof java.awt.Component) {
+ java.awt.Component comp = (java.awt.Component) source;
+ width=comp.getWidth();
+ height=comp.getHeight();
+ } else {
+ throw new RuntimeException("Event source neither Window nor Component: "+source);
+ }
+ float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)width);
+ float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)height);
+
+ prevMouseX = x;
+ prevMouseY = y;
+
+ view_rotx += thetaX;
+ view_roty += thetaY;
+ }
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java
new file mode 100644
index 000000000..d04ce3849
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java
@@ -0,0 +1,122 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.demos.gl2.gears;
+
+import javax.media.opengl.*;
+import com.jogamp.opengl.util.Animator;
+import javax.media.opengl.awt.GLCanvas;
+import com.jogamp.newt.event.awt.AWTKeyAdapter;
+import com.jogamp.newt.event.awt.AWTWindowAdapter;
+import com.jogamp.newt.event.TraceKeyAdapter;
+import com.jogamp.newt.event.TraceWindowAdapter;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.util.QuitAdapter;
+import java.awt.Frame;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+public class TestGearsAWT extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ glp = GLProfile.getDefault();
+ Assert.assertNotNull(glp);
+ width = 512;
+ height = 512;
+ }
+
+ @AfterClass
+ public static void releaseClass() {
+ }
+
+ protected void runTestGL(GLCapabilities caps) throws InterruptedException {
+ Frame frame = new Frame("Gears AWT Test");
+ Assert.assertNotNull(frame);
+
+ GLCanvas glCanvas = new GLCanvas(caps);
+ Assert.assertNotNull(glCanvas);
+ frame.add(glCanvas);
+ frame.setSize(512, 512);
+
+ glCanvas.addGLEventListener(new Gears());
+
+ Animator animator = new Animator(glCanvas);
+ QuitAdapter quitAdapter = new QuitAdapter();
+
+ new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter)).addTo(glCanvas);
+ new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter)).addTo(frame);
+
+ frame.setVisible(true);
+ animator.start();
+
+ while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getDuration()<duration) {
+ Thread.sleep(100);
+ }
+
+ Assert.assertNotNull(frame);
+ Assert.assertNotNull(glCanvas);
+ Assert.assertNotNull(animator);
+
+ animator.stop();
+ Assert.assertEquals(false, animator.isAnimating());
+ frame.setVisible(false);
+ Assert.assertEquals(false, frame.isVisible());
+ frame.remove(glCanvas);
+ frame.dispose();
+ frame=null;
+ glCanvas=null;
+ }
+
+ @Test
+ public void test01() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
+ runTestGL(caps);
+ }
+
+ static long duration = 500; // ms
+
+ public static void main(String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ try {
+ duration = Integer.parseInt(args[i]);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ }
+ }
+ org.junit.runner.JUnitCore.main(TestGearsAWT.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsGLJPanelAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsGLJPanelAWT.java
new file mode 100644
index 000000000..40e2ae933
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsGLJPanelAWT.java
@@ -0,0 +1,130 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.demos.gl2.gears;
+
+import javax.media.opengl.*;
+import com.jogamp.opengl.util.FPSAnimator;
+import javax.media.opengl.awt.GLJPanel;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import java.awt.AWTException;
+import java.awt.BorderLayout;
+import java.lang.reflect.InvocationTargetException;
+import javax.swing.JFrame;
+import javax.swing.SwingUtilities;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class TestGearsGLJPanelAWT extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(false);
+ glp = GLProfile.getDefault();
+ Assert.assertNotNull(glp);
+ width = 512;
+ height = 512;
+ }
+
+ @AfterClass
+ public static void releaseClass() {
+ }
+
+ protected void runTestGL(GLCapabilities caps)
+ throws AWTException, InterruptedException, InvocationTargetException
+ {
+ JFrame frame = new JFrame("Swing GLJPanel");
+ Assert.assertNotNull(frame);
+
+ GLJPanel glJPanel = new GLJPanel(caps);
+ Assert.assertNotNull(glJPanel);
+ glJPanel.addGLEventListener(new Gears());
+
+ FPSAnimator animator = new FPSAnimator(glJPanel, 60);
+
+ final JFrame _frame = frame;
+ final GLJPanel _glJPanel = glJPanel;
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ _frame.getContentPane().add(_glJPanel, BorderLayout.CENTER);
+ _frame.setSize(512, 512);
+ _frame.setVisible(true);
+ } } ) ;
+
+ animator.start();
+ Assert.assertEquals(true, animator.isAnimating());
+
+ while(animator.isAnimating() && animator.getDuration()<duration) {
+ Thread.sleep(100);
+ }
+
+ Assert.assertNotNull(frame);
+ Assert.assertNotNull(glJPanel);
+ Assert.assertNotNull(animator);
+
+ animator.stop();
+ Assert.assertEquals(false, animator.isAnimating());
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ _frame.setVisible(false);
+ _frame.getContentPane().remove(_glJPanel);
+ _frame.remove(_glJPanel);
+ _glJPanel.destroy();
+ _frame.dispose();
+ } } );
+ }
+
+ @Test
+ public void test01()
+ throws AWTException, InterruptedException, InvocationTargetException
+ {
+ GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
+ runTestGL(caps);
+ }
+
+ static long duration = 500; // ms
+
+ public static void main(String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ try {
+ duration = Integer.parseInt(args[i]);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ }
+ }
+ org.junit.runner.JUnitCore.main(TestGearsGLJPanelAWT.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/newt/TestGearsNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/newt/TestGearsNEWT.java
new file mode 100644
index 000000000..588fe725f
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/newt/TestGearsNEWT.java
@@ -0,0 +1,126 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.newt;
+
+import com.jogamp.newt.event.KeyAdapter;
+import com.jogamp.newt.event.KeyEvent;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.util.QuitAdapter;
+
+import com.jogamp.opengl.util.Animator;
+
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.GLRunnable;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+public class TestGearsNEWT extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ glp = GLProfile.getDefault();
+ Assert.assertNotNull(glp);
+ width = 512;
+ height = 512;
+ }
+
+ @AfterClass
+ public static void releaseClass() {
+ }
+
+ protected void runTestGL(GLCapabilities caps) throws InterruptedException {
+ GLWindow glWindow = GLWindow.create(caps);
+ Assert.assertNotNull(glWindow);
+ glWindow.setTitle("Gears NEWT Test");
+
+ glWindow.addGLEventListener(new Gears());
+
+ Animator animator = new Animator(glWindow);
+ QuitAdapter quitAdapter = new QuitAdapter();
+
+ //glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
+ //glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));
+ glWindow.addKeyListener(quitAdapter);
+ glWindow.addWindowListener(quitAdapter);
+
+ final GLWindow f_glWindow = glWindow;
+ glWindow.addKeyListener(new KeyAdapter() {
+ public void keyTyped(KeyEvent e) {
+ if(e.getKeyChar()=='f') {
+ f_glWindow.invoke(false, new GLRunnable() {
+ public void run(GLAutoDrawable drawable) {
+ GLWindow win = (GLWindow)drawable;
+ win.setFullscreen(!win.isFullscreen());
+ } });
+ }
+ }
+ });
+
+ glWindow.setSize(width, height);
+ glWindow.setVisible(true);
+ animator.start();
+
+ while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getDuration()<duration) {
+ Thread.sleep(100);
+ }
+
+ animator.stop();
+ glWindow.invalidate();
+ }
+
+ @Test
+ public void test01() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
+ runTestGL(caps);
+ }
+
+ static long duration = 500; // ms
+
+ public static void main(String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ try {
+ duration = Integer.parseInt(args[i]);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ }
+ }
+ org.junit.runner.JUnitCore.main(TestGearsNEWT.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/newt/TestGearsNewtAWTWrapper.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/newt/TestGearsNewtAWTWrapper.java
new file mode 100644
index 000000000..939a85631
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/newt/TestGearsNewtAWTWrapper.java
@@ -0,0 +1,114 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.newt;
+
+import javax.media.nativewindow.*;
+import javax.media.opengl.*;
+import com.jogamp.opengl.util.Animator;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.util.QuitAdapter;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.After;
+import org.junit.Test;
+
+public class TestGearsNewtAWTWrapper extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ glp = GLProfile.getDefault();
+ Assert.assertNotNull(glp);
+ width = 512;
+ height = 512;
+ }
+
+ @AfterClass
+ public static void releaseClass() {
+ }
+
+ protected void runTestGL(GLCapabilitiesImmutable caps) throws InterruptedException {
+ Display nDisplay = NewtFactory.createDisplay(NativeWindowFactory.TYPE_AWT, null, false); // local display
+ Screen nScreen = NewtFactory.createScreen(nDisplay, 0); // screen 0
+ Window nWindow = NewtFactory.createWindow(nScreen, caps);
+
+ GLWindow glWindow = GLWindow.create(nWindow);
+ Assert.assertNotNull(glWindow);
+ glWindow.setTitle("Gears NewtAWTWrapper Test");
+
+ glWindow.addGLEventListener(new Gears());
+
+ Animator animator = new Animator(glWindow);
+ QuitAdapter quitAdapter = new QuitAdapter();
+
+ glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
+ glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));
+
+ glWindow.setSize(width, height);
+ glWindow.setVisible(true);
+ animator.start();
+
+ while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getDuration()<duration) {
+ Thread.sleep(100);
+ }
+
+ animator.stop();
+ glWindow.invalidate();
+ }
+
+ @Test
+ public void test01() throws InterruptedException {
+ GLCapabilitiesImmutable caps = new GLCapabilities(GLProfile.getDefault());
+ runTestGL(caps);
+ }
+
+ static long duration = 500; // ms
+
+ public static void main(String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ try {
+ duration = Integer.parseInt(args[i]);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ }
+ }
+ org.junit.runner.JUnitCore.main(TestGearsNewtAWTWrapper.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/drawable/TestDrawable01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/drawable/TestDrawable01NEWT.java
new file mode 100644
index 000000000..8897dc6fe
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/drawable/TestDrawable01NEWT.java
@@ -0,0 +1,184 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.drawable;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import javax.media.opengl.*;
+
+import com.jogamp.newt.*;
+import java.io.IOException;
+
+public class TestDrawable01NEWT extends UITestCase {
+ static GLProfile glp;
+ static GLDrawableFactory factory;
+ static int width, height;
+ GLCapabilities caps;
+ Window window;
+ GLDrawable drawable;
+ GLContext context;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ glp = GLProfile.getDefault();
+ Assert.assertNotNull(glp);
+ factory = GLDrawableFactory.getFactory(glp);
+ Assert.assertNotNull(factory);
+ width = 640;
+ height = 480;
+ }
+
+ @AfterClass
+ public static void releaseClass() {
+ Assert.assertNotNull(factory);
+ factory=null;
+ }
+
+ @Before
+ public void initTest() {
+ caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ }
+
+ void createWindow(boolean onscreen, boolean pbuffer, boolean undecorated) {
+ caps.setOnscreen(onscreen);
+ caps.setPBuffer(!onscreen && pbuffer);
+ caps.setDoubleBuffered(onscreen);
+ // System.out.println("Requested: "+caps);
+
+ //
+ // Create native windowing resources .. X11/Win/OSX
+ //
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+
+ window = NewtFactory.createWindow(screen, caps);
+ Assert.assertNotNull(window);
+ window.setUndecorated(onscreen && undecorated);
+ window.setSize(width, height);
+ window.setVisible(true);
+ // System.out.println("Created: "+window);
+
+ //
+ // Create native OpenGL resources .. XGL/WGL/CGL ..
+ // equivalent to GLAutoDrawable methods: setVisible(true)
+ //
+ GLCapabilities glCaps = (GLCapabilities) window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities();
+ Assert.assertNotNull(glCaps);
+ Assert.assertTrue(glCaps.getGreenBits()>5);
+ Assert.assertTrue(glCaps.getBlueBits()>5);
+ Assert.assertTrue(glCaps.getRedBits()>5);
+ Assert.assertEquals(glCaps.isOnscreen(),onscreen);
+ Assert.assertTrue(onscreen || !pbuffer || glCaps.isPBuffer()); // pass if onscreen, or !pbuffer req. or have pbuffer
+ Assert.assertEquals(glCaps.getDoubleBuffered(),onscreen);
+ Assert.assertTrue(glCaps.getDepthBits()>4);
+
+ drawable = factory.createGLDrawable(window);
+ Assert.assertNotNull(drawable);
+ // System.out.println("Pre: "+drawable);
+ //
+ drawable.setRealized(true);
+ // Assert.assertEquals(width,drawable.getWidth());
+ // Assert.assertEquals(height,drawable.getHeight());
+ // Assert.assertEquals(glCaps,drawable.getChosenGLCapabilities());
+ Assert.assertEquals(window,drawable.getNativeSurface());
+ // System.out.println("Post: "+drawable);
+
+ context = drawable.createContext(null);
+ Assert.assertNotNull(context);
+ // System.out.println(context);
+
+ int res = context.makeCurrent();
+ Assert.assertTrue(GLContext.CONTEXT_CURRENT_NEW==res || GLContext.CONTEXT_CURRENT==res);
+
+ // draw something ..
+
+ drawable.swapBuffers();
+ context.release();
+
+ // System.out.println("Final: "+window);
+ }
+
+ void destroyWindow() {
+ // GLWindow.dispose(..) sequence
+ Assert.assertNotNull(context);
+ context.destroy();
+
+ Assert.assertNotNull(drawable);
+ drawable.setRealized(false);
+
+ // GLWindow.destroy(..) sequence cont..
+ Assert.assertNotNull(window);
+ window.invalidate();
+
+ drawable = null;
+ context = null;
+ window = null;
+ }
+
+ @Test
+ public void testOnScreenDecorated() throws InterruptedException {
+ createWindow(true, false, false);
+ Thread.sleep(1000); // 1000 ms
+ destroyWindow();
+ }
+
+ @Test
+ public void testOnScreenUndecorated() throws InterruptedException {
+ createWindow(true, false, true);
+ Thread.sleep(1000); // 1000 ms
+ destroyWindow();
+ }
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestDrawable01NEWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLSimple01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLSimple01NEWT.java
new file mode 100644
index 000000000..ed2f5d3cb
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLSimple01NEWT.java
@@ -0,0 +1,143 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.glsl;
+
+import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquare0;
+import com.jogamp.opengl.test.junit.util.GLSLSimpleProgram;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLContext;
+import javax.media.opengl.GLProfile;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.test.junit.jogl.demos.es2.shader.RedSquareShader;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
+
+import java.io.IOException;
+import javax.media.opengl.GL2ES2;
+import org.junit.AfterClass;
+
+public class TestGLSLSimple01NEWT extends UITestCase {
+ static long durationPerTest = 100; // ms
+
+ @BeforeClass
+ public static void initClass() {
+ System.err.println("class init");
+ GLProfile.initSingleton(true);
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ System.err.println("class tear down ..");
+ GLProfile.shutdown();
+ System.err.println("class tear down end");
+ }
+
+ @Test(timeout=60000)
+ public void testGLSLCompilation01() {
+ GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
+ Assert.assertNotNull(glp);
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+
+ GLWindow window = GLWindow.create(caps);
+ Assert.assertNotNull(window);
+ window.setSize(800, 600);
+ window.setVisible(true);
+ Assert.assertTrue(window.isNativeValid());
+
+ GLContext context = window.getContext();
+ context.setSynchronized(true);
+
+ // trigger native creation of drawable/context
+ window.display();
+ Assert.assertTrue(window.isRealized());
+ Assert.assertTrue(window.getContext().isCreated());
+
+ context.makeCurrent();
+
+ // given
+
+ GL2ES2 gl = context.getGL().getGL2ES2();
+ GLSLSimpleProgram myShader = GLSLSimpleProgram.create(gl,
+ RedSquareShader.VERTEX_SHADER_TEXT,
+ RedSquareShader.FRAGMENT_SHADER_TEXT,
+ true);
+
+ myShader.release(gl);
+ context.release();
+ window.destroy();
+ }
+
+ @Test(timeout=60000)
+ public void testGLSLUse01() throws InterruptedException {
+ GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
+ Assert.assertNotNull(glp);
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+
+ GLWindow window = GLWindow.create(caps);
+ Assert.assertNotNull(window);
+ window.setSize(800, 600);
+ window.setVisible(true);
+ Assert.assertTrue(window.isNativeValid());
+ window.addGLEventListener(new RedSquare0());
+
+ Animator animator = new Animator(window);
+ animator.start();
+ Assert.assertEquals(true, animator.isAnimating());
+ while(animator.isAnimating() && animator.getDuration()<durationPerTest) {
+ Thread.sleep(100);
+ }
+ Assert.assertEquals(true, animator.isAnimating());
+
+ window.destroy();
+ animator.stop();
+ }
+
+ public static void main(String args[]) throws IOException {
+ System.err.println("main - start");
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = MiscUtils.atoi(args[++i], (int)durationPerTest);
+ }
+ }
+ String tstname = TestGLSLSimple01NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ System.err.println("main - end");
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestTransformFeedbackVaryingsBug407NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestTransformFeedbackVaryingsBug407NEWT.java
new file mode 100644
index 000000000..be4873ff6
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestTransformFeedbackVaryingsBug407NEWT.java
@@ -0,0 +1,231 @@
+package com.jogamp.opengl.test.junit.jogl.glsl;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+import javax.media.opengl.GL3;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLContext;
+import javax.media.opengl.GLProfile;
+
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.util.glsl.ShaderUtil;
+
+import java.io.IOException;
+import org.junit.AfterClass;
+
+/**
+ * Bug 'Function glTransformFeedbackVaryings incorrectly passes argument'
+ * http://jogamp.org/bugzilla/show_bug.cgi?id=407
+ */
+public class TestTransformFeedbackVaryingsBug407NEWT extends UITestCase {
+
+ private String VERTEX_SHADER_TEXT;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ GLProfile.shutdown();
+ }
+
+ class MyShader {
+ int shaderProgram;
+ int vertShader;
+
+ MyShader(int shaderProgram, int vertShader) {
+ this.shaderProgram = shaderProgram;
+ this.vertShader = vertShader;
+ }
+ }
+
+ private MyShader getShader(GL3 gl, String text, int type) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintStream pbaos = new PrintStream(baos);
+
+ int shaderProgram = gl.glCreateProgram();
+
+ int vertShader = gl.glCreateShader(type);
+
+ String[] lines = new String[]{text};
+ int[] lengths = new int[]{lines[0].length()};
+ gl.glShaderSource(vertShader, lines.length, lines, lengths, 0);
+ gl.glCompileShader(vertShader);
+
+ if(!ShaderUtil.isShaderStatusValid(gl, vertShader, gl.GL_COMPILE_STATUS, pbaos)) {
+ System.out.println("getShader:postCompile: "+baos.toString());
+ Assert.assertTrue(false);
+ }
+ pbaos.flush(); baos.reset();
+
+ gl.glAttachShader(shaderProgram, vertShader);
+
+ return new MyShader(shaderProgram, vertShader);
+ }
+
+ private void releaseShader(GL3 gl, MyShader myShader) {
+ if(null!=myShader) {
+ gl.glDetachShader(myShader.shaderProgram, myShader.vertShader);
+ gl.glDeleteShader(myShader.vertShader);
+ gl.glDeleteProgram(myShader.shaderProgram);
+ }
+ }
+
+
+ private GLWindow prepareTest() {
+ if(!GLProfile.isGL3Available()) {
+ System.err.println("GL3 not available");
+ System.err.println(GLProfile.glAvailabilityToString());
+ return null;
+ }
+ VERTEX_SHADER_TEXT =
+ "#version 150 \n"
+ + " \n"
+ + "out vec4 Position; \n"
+ + " \n"
+ + "void main() { \n"
+ + " Position = vec4(1.0, 1.0, 1.0, 1.0); \n"
+ + "} \n";
+
+ GLCapabilities caps;
+
+ GLProfile glp = null;
+ try {
+ glp = GLProfile.get(GLProfile.GL3);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+ caps = new GLCapabilities(glp);
+
+ caps.setOnscreen(true);
+ caps.setDoubleBuffered(true);
+
+ GLWindow window = GLWindow.create(caps);
+ Assert.assertNotNull(window);
+ window.setUndecorated(true);
+ window.setSize(800, 600);
+ window.setVisible(true);
+ Assert.assertTrue(window.isNativeValid());
+
+ window.getContext().setSynchronized(true);
+
+ // trigger native creation of drawable/context
+ window.display();
+ Assert.assertTrue(window.isRealized());
+ Assert.assertTrue(window.getContext().isCreated());
+
+ return window;
+ }
+
+ private void cleanupTest(GLWindow window) {
+ if(null!=window) {
+ window.destroy();
+ }
+ }
+
+ @Test(timeout=60000)
+ public void testGlTransformFeedbackVaryings_WhenVarNameOK() {
+ if(!GLProfile.isGL3Available()) {
+ return;
+ }
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintStream pbaos = new PrintStream(baos);
+
+ GLWindow window = prepareTest();
+ GLContext context = window.getContext();
+ context.makeCurrent();
+
+ // given
+
+ GL3 gl = context.getGL().getGL3();
+ MyShader myShader = getShader(gl, VERTEX_SHADER_TEXT, GL3.GL_VERTEX_SHADER);
+ String[] vars = new String[]{"Position"};
+
+ // when
+
+ gl.glTransformFeedbackVaryings(myShader.shaderProgram, 1, vars, GL3.GL_SEPARATE_ATTRIBS);
+ gl.glLinkProgram(myShader.shaderProgram);
+
+ // then
+
+ boolean error = false;
+
+ if(!ShaderUtil.isProgramValid(gl, myShader.shaderProgram, pbaos)) {
+ System.out.println("Error (unexpected link error) - testGlTransformFeedbackVaryings_WhenVarNameOK:postLink: "+baos.toString());
+ error = true;
+ }
+ pbaos.flush(); baos.reset();
+
+ Assert.assertEquals(GL3.GL_NO_ERROR, gl.glGetError());
+
+ releaseShader(gl, myShader);
+ context.release();
+ cleanupTest(window);
+
+ Assert.assertFalse(error);
+ }
+
+ @Test(timeout=60000)
+ public void testGlTransformFeedbackVaryings_WhenVarNameWrong() {
+ if(!GLProfile.isGL3Available()) {
+ return;
+ }
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintStream pbaos = new PrintStream(baos);
+
+ GLWindow window = prepareTest();
+ GLContext context = window.getContext();
+ context.makeCurrent();
+
+ // given
+
+ GL3 gl = context.getGL().getGL3();
+ MyShader myShader = getShader(gl, VERTEX_SHADER_TEXT, GL3.GL_VERTEX_SHADER);
+ String[] vars = new String[]{"PPPosition"};
+
+ // when
+
+ gl.glTransformFeedbackVaryings(myShader.shaderProgram, 1, vars, GL3.GL_SEPARATE_ATTRIBS);
+ gl.glLinkProgram(myShader.shaderProgram);
+
+ // then
+
+ boolean error = false;
+
+ if(!ShaderUtil.isProgramValid(gl, myShader.shaderProgram, pbaos)) {
+ System.out.println("GOOD (expected link error) - testGlTransformFeedbackVaryings_WhenVarNameWrong:postLink: "+baos.toString());
+ // should be invalid, due to wrong var name
+ } else {
+ // oops
+ System.out.println("Error (unexpected link success) - testGlTransformFeedbackVaryings_WhenVarNameWrong link worked, but it should not");
+ error = true;
+ }
+ pbaos.flush(); baos.reset();
+
+ Assert.assertEquals(GL3.GL_NO_ERROR, gl.glGetError());
+ // You cannot assume this error message - Assert.assertTrue(baos.toString().contains("(named PPPosition)"));
+
+ releaseShader(gl, myShader);
+ context.release();
+ cleanupTest(window);
+
+ Assert.assertFalse(error);
+ }
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestTransformFeedbackVaryingsBug407NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java b/src/test/com/jogamp/opengl/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java
new file mode 100644
index 000000000..21a97363c
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java
@@ -0,0 +1,333 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.newt;
+
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+import com.jogamp.opengl.test.junit.util.*;
+
+import java.lang.reflect.InvocationTargetException;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.awt.GLCanvas;
+import com.jogamp.opengl.util.Animator;
+
+import com.jogamp.newt.Screen;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.newt.awt.NewtCanvasAWT;
+
+import java.awt.BorderLayout;
+import java.awt.Canvas;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.AWTException;
+import java.awt.Robot;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.event.InputEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import javax.media.opengl.GLEventListener;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.BorderFactory;
+import javax.swing.border.Border;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+public class TestSwingAWTRobotUsageBeforeJOGLInitBug411 extends UITestCase {
+ static long durationPerTest = 500; // ms
+ static Robot robot;
+ static Border border;
+ static JFrame frame;
+ static JButton button;
+ static JPanel panel;
+ static JPanel colorPanel;
+ static boolean windowClosing;
+
+ boolean modLightBrighter = true;
+
+ Color modLight(Color c) {
+ Color c2;
+ if(modLightBrighter) {
+ c2 = c.brighter();
+ } else {
+ c2 = c.darker();
+ }
+ if(c2.equals(c)) {
+ modLightBrighter = !modLightBrighter;
+ }
+ return c2;
+ }
+
+ class SwingGLAction implements GLEventListener {
+ public void init(GLAutoDrawable glad) {
+ }
+
+ public void dispose(GLAutoDrawable glad) {
+ }
+
+ public void display(GLAutoDrawable glad) {
+ colorPanel.setBackground(modLight(colorPanel.getBackground()));
+ colorPanel.repaint();
+ }
+
+ public void reshape(GLAutoDrawable glad, final int x, final int y, final int width, final int height) {
+ }
+ }
+
+ @BeforeClass
+ public static void setup() throws InterruptedException, InvocationTargetException, AWTException {
+ int count;
+
+ System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.setup(): Start Pre-JOGL-Swing");
+
+ // GLProfile.initSingleton(false);
+ // GLProfile.initSingleton(true);
+
+ // simulate AWT usage before JOGL's initialization of X11 threading
+ windowClosing=false;
+ border = BorderFactory.createLineBorder (Color.yellow, 2);
+
+ panel = new JPanel();
+ panel.setLayout(new BorderLayout());
+
+ button = new JButton("Click me");
+ button.addMouseListener(new MouseAdapter() {
+ public void mouseClicked(MouseEvent e) {
+ System.err.println("Test: "+e);
+ }
+ });
+ panel.add(button, BorderLayout.NORTH);
+
+ colorPanel = new JPanel();
+ Dimension size = new Dimension(400,100);
+ colorPanel.setPreferredSize(size);
+ colorPanel.setBorder(border);
+ panel.add(colorPanel, BorderLayout.SOUTH);
+
+ frame = new JFrame("PRE JOGL");
+ frame.addWindowListener( new WindowAdapter() {
+ public void windowClosing(WindowEvent ev) {
+ windowClosing=true;
+ }
+ });
+ frame.setContentPane(panel);
+ frame.setSize(512, 512);
+ frame.setLocation(0, 0);
+ frame.pack();
+
+ // AWT/Swing: From here on (post setVisible(true)
+ // you need to use AWT/Swing's invokeAndWait()
+
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.setVisible(true);
+ colorPanel.setBackground(Color.white);
+ colorPanel.repaint();
+ }});
+
+ robot = new Robot();
+ robot.setAutoWaitForIdle(true);
+
+ AWTRobotUtil.toFront(robot, frame);
+ AWTRobotUtil.requestFocus(robot, button);
+
+ System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.setup(): Before JOGL init");
+
+ GLProfile.initSingleton(false);
+
+ System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.setup(): End Pre-JOGL-Swing");
+ }
+
+ @AfterClass
+ public static void release() throws InterruptedException, InvocationTargetException {
+ System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.release(): Start");
+ robot = null;
+ Assert.assertNotNull(frame);
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.dispose();
+ }
+ });
+ frame=null;
+ System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.release(): End");
+ }
+
+ protected void runTestGL(final Canvas canvas, GLAutoDrawable drawable)
+ throws AWTException, InterruptedException, InvocationTargetException {
+
+ Dimension size = new Dimension(400,400);
+ canvas.setPreferredSize(size);
+
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ panel.add(canvas, BorderLayout.CENTER);
+ frame.pack();
+ }
+ });
+
+ AWTRobotUtil.toFront(robot, frame);
+
+ drawable.addGLEventListener(new Gears());
+
+ for(int i=0; i<100; i++) {
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ colorPanel.setBackground(modLight(colorPanel.getBackground()));
+ colorPanel.repaint();
+ }
+ });
+ drawable.display(); // one in process display
+ Thread.sleep(10);
+ }
+
+ colorPanel.setBackground(Color.blue);
+ drawable.addGLEventListener(new SwingGLAction());
+
+ Point p0 = canvas.getLocationOnScreen();
+ Rectangle r0 = canvas.getBounds();
+ robot.mouseMove( (int) ( p0.getX() + .5 ) ,
+ (int) ( p0.getY() + .5 ) );
+ robot.mousePress(InputEvent.BUTTON1_MASK);
+ for(int i=0; !windowClosing && i<durationPerTest/10; i++) {
+ p0.translate(1,1);
+ robot.mouseMove( (int) ( p0.getX() + .5 ) ,
+ (int) ( p0.getY() + .5 ) );
+ Thread.sleep(10);
+ }
+ robot.mouseRelease(InputEvent.BUTTON1_MASK);
+
+ for(int i=0; !windowClosing && i<durationPerTest/100; i++) {
+ Thread.sleep(100);
+ }
+
+ Assert.assertNotNull(canvas);
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ panel.remove(canvas);
+ frame.pack();
+ }
+ });
+ }
+
+ @Test
+ public void test01NewtCanvasAWT() throws AWTException, InterruptedException, InvocationTargetException {
+ System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.test01NewtCanvasAWT(): Start");
+
+ GLProfile glp = GLProfile.getDefault();
+ GLCapabilities caps = new GLCapabilities(glp);
+
+ GLWindow win0 = GLWindow.create(caps);
+ win0.setSize(100,100);
+ win0.setVisible(true);
+ Screen screen = win0.getScreen();
+ win0.setPosition(screen.getWidth()-150, 0);
+ win0.addGLEventListener(new Gears());
+ Animator anim = new Animator(win0);
+ anim.start();
+
+ GLWindow win1 = GLWindow.create(caps);
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(win1);
+ anim.add(win1);
+ runTestGL(newtCanvasAWT, win1);
+
+ win0.destroy();
+ Assert.assertEquals(true, anim.isAnimating());
+
+ newtCanvasAWT.destroy();
+
+ win0.invalidate();
+ Assert.assertEquals(true, anim.isAnimating());
+ win1.invalidate();
+ Assert.assertEquals(false, anim.isAnimating());
+
+ anim.stop();
+
+ System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.test01NewtCanvasAWT(): End");
+ }
+
+ @Test
+ public void test02GLCanvas() throws AWTException, InterruptedException, InvocationTargetException {
+ System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.test02GLCanvas(): Start");
+ GLProfile glp = GLProfile.getDefault();
+ GLCapabilities caps = new GLCapabilities(glp);
+
+ Animator anim = new Animator();
+ anim.start();
+
+ /**
+ * Using GLCanvas _and_ NEWT side by side currently causes a deadlock
+ * in AWT with AMD drivers !
+ *
+ GLWindow win0 = GLWindow.create(caps);
+ win0.setSize(100,100);
+ win0.setVisible(true);
+ Screen screen = win0.getScreen();
+ win0.setPosition(screen.getWidth()-150, 0);
+ win0.addGLEventListener(new Gears());
+ anim.add(win0);
+ */
+
+ GLCanvas glCanvas = new GLCanvas(caps);
+ anim.add(glCanvas);
+ runTestGL(glCanvas, glCanvas);
+
+ /**
+ win0.destroy();
+ Assert.assertEquals(true, anim.isAnimating());
+ */
+ anim.stop();
+ System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.test02GLCanvas(): End");
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ System.out.println("durationPerTest: "+durationPerTest);
+ org.junit.runner.JUnitCore.main(TestSwingAWTRobotUsageBeforeJOGLInitBug411.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2File.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2File.java
new file mode 100644
index 000000000..95e7d6e53
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2File.java
@@ -0,0 +1,70 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.offscreen;
+
+import java.io.IOException;
+import javax.media.opengl.*;
+
+import com.jogamp.opengl.util.texture.TextureIO;
+import java.io.File;
+
+public class ReadBuffer2File extends ReadBufferBase {
+
+ public ReadBuffer2File(GLDrawable externalRead) {
+ super(externalRead);
+ }
+
+ @Override
+ public void dispose(GLAutoDrawable drawable) {
+ super.dispose(drawable);
+ }
+ int shotNum = 0;
+
+ void copyTextureData2File() throws IOException {
+ if (!readBufferUtil.isValid()) {
+ return;
+ }
+
+ File file = File.createTempFile("shot" + shotNum + "-", ".ppm");
+ TextureIO.write(readBufferUtil.getTextureData(), file);
+ System.out.println("Wrote: " + file.getAbsolutePath() + ", ...");
+ shotNum++;
+ readBufferUtil.rewindPixelBuffer();
+ }
+
+ @Override
+ public void display(GLAutoDrawable drawable) {
+ super.display(drawable);
+ try {
+ copyTextureData2File();
+ } catch (IOException ex) {
+ throw new RuntimeException("can not read buffer to file", ex);
+ }
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2Screen.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2Screen.java
new file mode 100644
index 000000000..96a830a53
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBuffer2Screen.java
@@ -0,0 +1,188 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.offscreen;
+
+import java.nio.*;
+import javax.media.opengl.*;
+import javax.media.opengl.fixedfunc.*;
+
+import com.jogamp.opengl.util.*;
+
+import javax.media.opengl.fixedfunc.GLPointerFunc;
+import com.jogamp.opengl.util.texture.TextureCoords;
+import com.jogamp.opengl.util.GLArrayDataClient;
+import com.jogamp.opengl.util.GLArrayDataServer;
+
+public class ReadBuffer2Screen extends ReadBufferBase {
+ PMVMatrix pmvMatrix;
+ GLArrayDataClient readTextureVertices = null;
+ GLArrayDataClient readTextureCoords = null;
+ boolean enableBufferAlways = false; // FIXME
+ boolean enableBufferVBO = true; // FIXME
+
+ public ReadBuffer2Screen (GLDrawable externalRead) {
+ super(externalRead);
+ }
+
+ @Override
+ public void init(GLAutoDrawable drawable) {
+ super.init(drawable);
+
+ GL gl = drawable.getGL();
+
+ pmvMatrix = new PMVMatrix();
+
+ float f_edge = 1f;
+ if(null==readTextureVertices) {
+ //readTextureVertices = GLArrayDataClient.createFixed(gl, GLPointerFunc.GL_VERTEX_ARRAY, "mgl_Vertex",
+ // 2, GL.GL_FLOAT, true, 4);
+ readTextureVertices = GLArrayDataServer.createFixed(gl, GLPointerFunc.GL_VERTEX_ARRAY, "mgl_Vertex",
+ 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW);
+ readTextureVertices.setEnableAlways(enableBufferAlways);
+ readTextureVertices.setVBOUsage(enableBufferVBO);
+ {
+ FloatBuffer vb = (FloatBuffer)readTextureVertices.getBuffer();
+ vb.put(-f_edge); vb.put(-f_edge);
+ vb.put( f_edge); vb.put(-f_edge);
+ vb.put(-f_edge); vb.put( f_edge);
+ vb.put( f_edge); vb.put( f_edge);
+ }
+ readTextureVertices.seal(gl, true);
+ System.out.println(readTextureVertices);
+ }
+
+ // Clear background to gray
+ gl.glClearColor(0.5f, 0.5f, 0.5f, 0.4f);
+ }
+
+ @Override
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ super.reshape(drawable, x, y, width, height);
+
+ GL gl = drawable.getGL();
+
+ gl.glViewport(0, 0, width, height);
+
+ if(gl instanceof GLLightingFunc) {
+ ((GLLightingFunc)gl).glShadeModel(GLLightingFunc.GL_SMOOTH);
+ }
+
+ GLMatrixFunc glM;
+ if(gl instanceof GLMatrixFunc) {
+ glM = (GLMatrixFunc)gl;
+ } else {
+ throw new GLException("ES2 currently unhandled .. ");
+ }
+
+ // Identity ..
+ pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW);
+ pmvMatrix.glLoadIdentity();
+ pmvMatrix.glTranslatef(0, 0, -2.5f);
+ if(null!=glM) {
+ glM.glMatrixMode(PMVMatrix.GL_MODELVIEW);
+ glM.glLoadMatrixf(pmvMatrix.glGetMvMatrixf());
+ }
+
+ // Set location in front of camera
+ pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION);
+ pmvMatrix.glLoadIdentity();
+ pmvMatrix.gluPerspective(45.0f, (float)width / (float)height, 1.0f, 100.0f);
+ if(null!=glM) {
+ glM.glMatrixMode(PMVMatrix.GL_PROJECTION);
+ glM.glLoadMatrixf(pmvMatrix.glGetPMatrixf());
+ }
+ }
+
+ @Override
+ public void dispose(GLAutoDrawable drawable) {
+ super.dispose(drawable);
+ }
+
+ void renderOffscreenTexture(GL gl) {
+ if(!readBufferUtil.isValid()) return;
+
+ // Now draw one quad with the texture
+ readBufferUtil.getTexture().enable();
+ readBufferUtil.getTexture().bind();
+
+ if(gl.isGL2ES1()) {
+ // gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_TEXTURE_ENV_MODE, GL2ES1.GL_REPLACE);
+ gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_TEXTURE_ENV_MODE, GL2ES1.GL_MODULATE);
+ }
+
+ updateTextureCoords(gl, false);
+
+ readTextureVertices.enableBuffer(gl, true);
+ if(null!=readTextureCoords) {
+ readTextureCoords.enableBuffer(gl, true);
+ }
+ gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, readTextureVertices.getElementNumber());
+ /**
+ if(null!=readTextureCoords) {
+ readTextureCoords.enableBuffer(gl, false);
+ }
+ readTextureVertices.enableBuffer(gl, false); */
+
+ readBufferUtil.getTexture().disable();
+ }
+
+ void updateTextureCoords(GL gl, boolean force) {
+ if(force || null==readTextureCoords) {
+ readTextureCoords = GLArrayDataServer.createFixed(gl, GLPointerFunc.GL_TEXTURE_COORD_ARRAY, "mgl_MultiTexCoord0",
+ 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW);
+ readTextureCoords.setEnableAlways(enableBufferAlways);
+ readTextureCoords.setVBOUsage(enableBufferVBO);
+ {
+ TextureCoords coords = readBufferUtil.getTexture().getImageTexCoords();
+ FloatBuffer cb = (FloatBuffer)readTextureCoords.getBuffer();
+ cb.put(coords.left()); cb.put(coords.bottom());
+ cb.put(coords.right()); cb.put(coords.bottom());
+ cb.put(coords.left()); cb.put(coords.top());
+ cb.put(coords.right()); cb.put(coords.top());
+ }
+ readTextureCoords.seal(gl, true);
+ System.out.println(readTextureCoords);
+ }
+ }
+
+ @Override
+ public void display(GLAutoDrawable drawable) {
+ super.display(drawable);
+
+ GL gl = drawable.getGL();
+
+ gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
+ if(gl instanceof GLLightingFunc) {
+ ((GLLightingFunc)gl).glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
+ }
+
+ renderOffscreenTexture(gl);
+ }
+}
+
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBufferBase.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBufferBase.java
new file mode 100644
index 000000000..71a73a7e1
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBufferBase.java
@@ -0,0 +1,91 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.offscreen;
+
+import javax.media.opengl.*;
+
+public class ReadBufferBase implements GLEventListener {
+ public boolean glDebug = false ;
+ public boolean glTrace = false ;
+
+ protected GLDrawable externalRead;
+
+ ReadBufferUtil readBufferUtil = new ReadBufferUtil();
+
+ public ReadBufferBase (GLDrawable externalRead) {
+ this.externalRead = externalRead ;
+ }
+
+ public void init(GLAutoDrawable drawable) {
+ GL _gl = drawable.getGL();
+
+ _gl.glGetError(); // flush error ..
+
+ if(glDebug) {
+ try {
+ _gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", null, _gl, null) );
+ } catch (Exception e) {
+ throw new RuntimeException("can not set debug pipeline", e);
+ }
+ }
+
+ if(glTrace) {
+ try {
+ _gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", null, _gl, new Object[] { System.err } ) );
+ } catch (Exception e) {
+ throw new RuntimeException("can not set trace pipeline", e);
+ }
+ }
+
+ System.out.println(_gl);
+
+ _gl.getContext().setGLReadDrawable(externalRead);
+ if(_gl.isGL2GL3()) {
+ _gl.getGL2GL3().glReadBuffer(GL2GL3.GL_FRONT);
+ }
+ System.out.println("---------------------------");
+ System.out.println(_gl.getContext());
+ System.out.println("---------------------------");
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ readBufferUtil.dispose();
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ GL gl = drawable.getGL();
+
+ readBufferUtil.fetchOffscreenTexture(drawable, gl);
+ }
+
+}
+
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBufferUtil.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBufferUtil.java
new file mode 100644
index 000000000..d4fa0d654
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/ReadBufferUtil.java
@@ -0,0 +1,107 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.offscreen;
+
+import com.jogamp.opengl.util.GLBuffers;
+import java.nio.*;
+import javax.media.opengl.*;
+
+import com.jogamp.opengl.util.texture.Texture;
+import com.jogamp.opengl.util.texture.TextureData;
+
+public class ReadBufferUtil {
+ protected int readPixelSizeLast = 0;
+ protected Buffer readPixelBuffer = null;
+ protected TextureData readTextureData = null;
+ protected Texture readTexture = new Texture(GL.GL_TEXTURE_2D);
+
+ public Buffer getPixelBuffer() { return readPixelBuffer; }
+ public void rewindPixelBuffer() { readPixelBuffer.rewind(); }
+
+ public TextureData getTextureData() { return readTextureData; }
+ public Texture getTexture() { return readTexture; }
+
+ public boolean isValid() {
+ return null!=readTexture && null!=readTextureData && null!=readPixelBuffer ;
+ }
+
+ public void fetchOffscreenTexture(GLDrawable drawable, GL gl) {
+ int readPixelSize = drawable.getWidth() * drawable.getHeight() * 3 ; // RGB
+ boolean newData = false;
+ if(readPixelSize>readPixelSizeLast) {
+ readPixelBuffer = GLBuffers.newDirectGLBuffer(GL.GL_UNSIGNED_BYTE, readPixelSize);
+ readPixelSizeLast = readPixelSize ;
+ try {
+ readTextureData = new TextureData(
+ gl.getGLProfile(),
+ // gl.isGL2GL3()?gl.GL_RGBA:gl.GL_RGB,
+ gl.GL_RGB,
+ drawable.getWidth(), drawable.getHeight(),
+ 0,
+ gl.GL_RGB,
+ gl.GL_UNSIGNED_BYTE,
+ false, false,
+ false /* flip */,
+ readPixelBuffer,
+ null /* Flusher */);
+ newData = true;
+ } catch (Exception e) {
+ readTextureData = null;
+ readPixelBuffer = null;
+ readPixelSizeLast = 0;
+ throw new RuntimeException("can not fetch offscreen texture", e);
+ }
+ }
+ if(null!=readPixelBuffer) {
+ readPixelBuffer.clear();
+ gl.glReadPixels(0, 0, drawable.getWidth(), drawable.getHeight(), GL.GL_RGB, GL.GL_UNSIGNED_BYTE, readPixelBuffer);
+ readPixelBuffer.rewind();
+ if(newData) {
+ readTexture.updateImage(readTextureData);
+ } else {
+ readTexture.updateSubImage(readTextureData, 0,
+ 0, 0, // src offset
+ 0, 0, // dst offset
+ drawable.getWidth(), drawable.getHeight());
+ }
+ readPixelBuffer.rewind();
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ public void dispose() {
+ readTexture.dispose();
+ readTextureData = null;
+ readPixelBuffer.clear();
+ readPixelBuffer = null;
+ readPixelSizeLast = 0;
+ }
+
+}
+
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/Surface2File.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/Surface2File.java
new file mode 100644
index 000000000..6be732a63
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/Surface2File.java
@@ -0,0 +1,79 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.offscreen;
+
+import javax.media.opengl.*;
+
+import com.jogamp.opengl.util.texture.TextureIO;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.media.nativewindow.*;
+
+public class Surface2File implements SurfaceUpdatedListener {
+
+ ReadBufferUtil readBufferUtil = new ReadBufferUtil();
+ int shotNum = 0;
+
+ public void dispose() {
+ readBufferUtil.dispose();
+ }
+
+ public void surfaceUpdated(Object updater, NativeSurface ns, long when) {
+ if (updater instanceof GLDrawable) {
+ GLDrawable drawable = (GLDrawable) updater;
+ GLContext ctx = GLContext.getCurrent();
+ if (null != ctx && ctx.getGLDrawable() == drawable) {
+ GL gl = ctx.getGL();
+ // FIXME glFinish() is an expensive paranoia sync, should not be necessary due to spec
+ gl.glFinish();
+ readBufferUtil.fetchOffscreenTexture(drawable, gl);
+ gl.glFinish();
+ try {
+ surface2File("shot");
+ } catch (IOException ex) {
+ throw new RuntimeException("can not write survace to file", ex);
+ }
+ }
+ }
+ }
+
+ public void surface2File(String basename) throws IOException {
+ if (!readBufferUtil.isValid()) {
+ return;
+ }
+
+ File file = File.createTempFile(basename + shotNum + "-", ".ppm");
+ TextureIO.write(readBufferUtil.getTextureData(), file);
+ System.out.println("Wrote: " + file.getAbsolutePath() + ", ...");
+ shotNum++;
+ readBufferUtil.rewindPixelBuffer();
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/TestOffscreen01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/TestOffscreen01NEWT.java
new file mode 100644
index 000000000..8851e4f7f
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/TestOffscreen01NEWT.java
@@ -0,0 +1,489 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.offscreen;
+
+
+import com.jogamp.newt.Display;
+import com.jogamp.newt.NewtFactory;
+import com.jogamp.newt.Screen;
+import com.jogamp.newt.Window;
+import com.jogamp.newt.event.MouseListener;
+import com.jogamp.newt.event.WindowListener;
+import com.jogamp.newt.opengl.GLWindow;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquare;
+import java.io.IOException;
+
+public class TestOffscreen01NEWT extends UITestCase {
+ static GLProfile glpDefault;
+ static GLDrawableFactory glDrawableFactory;
+ static int width, height;
+ GLCapabilities capsDefault;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ glpDefault = GLProfile.getDefault();
+ Assert.assertNotNull(glpDefault);
+ glDrawableFactory = GLDrawableFactory.getFactory(glpDefault);
+ System.out.println("INFO: PBuffer supported: "+ glDrawableFactory.canCreateGLPbuffer(null));
+ width = 640;
+ height = 480;
+ }
+
+ @AfterClass
+ public static void releaseClass() {
+ }
+
+ @Before
+ public void init() {
+ capsDefault = new GLCapabilities(glpDefault);
+ Assert.assertNotNull(capsDefault);
+ }
+
+ private void do01OffscreenWindowPBuffer(GLCapabilities caps) {
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+ Window window = NewtFactory.createWindow(screen, caps);
+ Assert.assertNotNull(window);
+ window.setSize(width, height);
+ GLWindow glWindow = GLWindow.create(window);
+ Assert.assertNotNull(glWindow);
+ try {
+ glWindow.setVisible(true);
+ } catch (Throwable t) {
+ // stop test and ignore if pixmap cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+ GLEventListener demo = new RedSquare();
+ WindowUtilNEWT.setDemoFields(demo, window, glWindow, false);
+ glWindow.addGLEventListener(demo);
+
+ while ( glWindow.getTotalFrames() < 2) {
+ try {
+ glWindow.display();
+ } catch (Throwable t) {
+ // stop test and ignore if pbuffer cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+ }
+
+ if(null!=glWindow) {
+ glWindow.destroy();
+ }
+ if(null!=window) {
+ window.destroy();
+ }
+ if(null!=screen) {
+ screen.destroy();
+ }
+ if(null!=display) {
+ display.destroy();
+ }
+ }
+
+ @Test
+ public void test01aOffscreenWindowPBuffer() {
+ if(!glDrawableFactory.canCreateGLPbuffer(null)) {
+ System.out.println("WARNING: PBuffer not supported on this platform - cannot test");
+ return;
+ }
+ GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false);
+ do01OffscreenWindowPBuffer(caps2);
+ }
+
+ @Test
+ public void test01bOffscreenWindowPBufferStencil() {
+ if(!glDrawableFactory.canCreateGLPbuffer(null)) {
+ System.out.println("WARNING: PBuffer not supported on this platform - cannot test");
+ return;
+ }
+ GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false);
+ caps2.setStencilBits(8);
+ do01OffscreenWindowPBuffer(caps2);
+ }
+
+ @Test
+ public void test01cOffscreenWindowPBufferStencilAlpha() {
+ if(!glDrawableFactory.canCreateGLPbuffer(null)) {
+ System.out.println("WARNING: PBuffer not supported on this platform - cannot test");
+ return;
+ }
+ GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false);
+ caps2.setStencilBits(8);
+ caps2.setAlphaBits(8);
+ do01OffscreenWindowPBuffer(caps2);
+ }
+
+ @Test
+ public void test01cOffscreenWindowPBuffer555() {
+ if(!glDrawableFactory.canCreateGLPbuffer(null)) {
+ System.out.println("WARNING: PBuffer not supported on this platform - cannot test");
+ return;
+ }
+ GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false);
+ caps2.setRedBits(5);
+ caps2.setGreenBits(5);
+ caps2.setBlueBits(5);
+ do01OffscreenWindowPBuffer(caps2);
+ }
+
+ @Test
+ public void test02Offscreen3Windows1DisplayPBuffer() {
+ if(!glDrawableFactory.canCreateGLPbuffer(null)) {
+ System.out.println("WARNING: PBuffer not supported on this platform - cannot test");
+ return;
+ }
+ GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false);
+ int winnum = 3, i;
+ Window windows[] = new Window[winnum];
+ GLWindow glWindows[] = new GLWindow[winnum];
+ GLEventListener demos[] = new GLEventListener[winnum];
+
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+
+ for(i=0; i<winnum; i++) {
+ System.out.println("Create Window "+i);
+ windows[i] = NewtFactory.createWindow(screen, caps2);
+ Assert.assertNotNull(windows[i]);
+ windows[i].setSize(width, height);
+ glWindows[i] = GLWindow.create(windows[i]);
+ Assert.assertNotNull(glWindows[i]);
+ try {
+ glWindows[i].setVisible(true);
+ } catch (Throwable t) {
+ // stop test and ignore if pixmap cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+ demos[i] = new RedSquare();
+ WindowUtilNEWT.setDemoFields(demos[i], windows[i], glWindows[i], false);
+ glWindows[i].addGLEventListener(demos[i]);
+ }
+
+ try {
+ while ( glWindows[0].getTotalFrames() < 2) {
+ for(i=0; i<winnum; i++) {
+ glWindows[i].display();
+ }
+ }
+ } catch (Throwable t) {
+ // stop test and ignore if pbuffer cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+
+ for(i=0; i<winnum; i++) {
+ if(null!=glWindows[i]) {
+ glWindows[i].destroy();
+ }
+ if(null!=windows[i]) {
+ windows[i].destroy();
+ }
+ }
+ if(null!=screen) {
+ screen.destroy();
+ }
+ if(null!=display) {
+ display.destroy();
+ }
+ }
+
+ @Test
+ public void test03Offscreen3Windows3DisplaysPBuffer() {
+ if(!glDrawableFactory.canCreateGLPbuffer(null)) {
+ System.out.println("WARNING: PBuffer not supported on this platform - cannot test");
+ return;
+ }
+ GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false);
+ int winnum = 3, i;
+ Display displays[] = new Display[winnum];
+ Screen screens[] = new Screen[winnum];
+ Window windows[] = new Window[winnum];
+ GLWindow glWindows[] = new GLWindow[winnum];
+ GLEventListener demos[] = new GLEventListener[winnum];
+
+ for(i=0; i<winnum; i++) {
+ System.out.println("Create Window "+i);
+ displays[i] = NewtFactory.createDisplay(null, false); // local display
+ Assert.assertNotNull(displays[i]);
+ screens[i] = NewtFactory.createScreen(displays[i], 0); // screen 0
+ Assert.assertNotNull(screens[i]);
+ windows[i] = NewtFactory.createWindow(screens[i], caps2);
+ Assert.assertNotNull(windows[i]);
+ windows[i].setSize(width, height);
+ glWindows[i] = GLWindow.create(windows[i]);
+ Assert.assertNotNull(glWindows[i]);
+ try {
+ glWindows[i].setVisible(true);
+ } catch (Throwable t) {
+ // stop test and ignore if pixmap cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+ demos[i] = new RedSquare();
+ WindowUtilNEWT.setDemoFields(demos[i], windows[i], glWindows[i], false);
+ glWindows[i].addGLEventListener(demos[i]);
+ }
+
+ try {
+ while ( glWindows[0].getTotalFrames() < 2) {
+ for(i=0; i<winnum; i++) {
+ glWindows[i].display();
+ }
+ }
+ } catch (Throwable t) {
+ // stop test and ignore if pbuffer cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+
+
+ for(i=0; i<winnum; i++) {
+ if(null!=glWindows[i]) {
+ glWindows[i].destroy();
+ }
+ if(null!=windows[i]) {
+ windows[i].destroy();
+ }
+ if(null!=screens[i]) {
+ screens[i].destroy();
+ }
+ if(null!=displays[i]) {
+ displays[i].destroy();
+ }
+ }
+ }
+
+ @Test
+ public void test04OffscreenSnapshotWithDemoPBuffer() {
+ if(!glDrawableFactory.canCreateGLPbuffer(null)) {
+ System.out.println("WARNING: PBuffer not supported on this platform - cannot test");
+ return;
+ }
+ GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false);
+
+ System.out.println("Create Window 1");
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+ Window window = NewtFactory.createWindow(screen, caps2);
+ Assert.assertNotNull(window);
+ window.setSize(width, height);
+ GLWindow glWindow = GLWindow.create(window);
+ Assert.assertNotNull(glWindow);
+ try {
+ glWindow.setVisible(true);
+ } catch (Throwable t) {
+ // stop test and ignore if pixmap cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+
+ GLWindow windowOnScreen = null;
+ WindowListener wl=null;
+ MouseListener ml=null;
+ SurfaceUpdatedListener ul=null;
+
+ GLEventListener demo = new RedSquare();
+ Assert.assertNotNull(demo);
+
+ try {
+ WindowUtilNEWT.run(glWindow, demo, windowOnScreen, wl, ml, ul, 2, true /*snapshot*/, false /*debug*/);
+ } catch (Throwable t) {
+ // stop test and ignore if pbuffer cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+
+ if(null!=windowOnScreen) {
+ windowOnScreen.destroy();
+ }
+ if(null!=glWindow) {
+ glWindow.destroy();
+ }
+ if(null!=window) {
+ window.destroy();
+ }
+ if(null!=screen) {
+ screen.destroy();
+ }
+ if(null!=display) {
+ display.destroy();
+ }
+ }
+
+ @Test
+ public void test11OffscreenWindowPixmap() {
+ // Offscreen doesn't work on >= GL3 (ATI)
+ GLProfile glp = GLProfile.get(GLProfile.GL2);
+ Assert.assertNotNull(glp);
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+
+ GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, false, false);
+
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+ Window window = NewtFactory.createWindow(screen, caps2);
+ Assert.assertNotNull(window);
+ window.setSize(width, height);
+ GLWindow glWindow = GLWindow.create(window);
+ Assert.assertNotNull(glWindow);
+ try {
+ glWindow.setVisible(true);
+ } catch (Throwable t) {
+ // stop test and ignore if pixmap cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+ GLEventListener demo = new RedSquare();
+ WindowUtilNEWT.setDemoFields(demo, window, glWindow, false);
+ glWindow.addGLEventListener(demo);
+
+ while ( glWindow.getTotalFrames() < 2) {
+ try {
+ glWindow.display();
+ } catch (Throwable t) {
+ // stop test and ignore if pixmap cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+ }
+
+ if(null!=glWindow) {
+ glWindow.destroy();
+ }
+ if(null!=window) {
+ window.destroy();
+ }
+ if(null!=screen) {
+ screen.destroy();
+ }
+ if(null!=display) {
+ display.destroy();
+ }
+ }
+
+ @Test
+ public void test14OffscreenSnapshotWithDemoPixmap() {
+ // Offscreen doesn't work on >= GL3 (ATI)
+ GLProfile glp = GLProfile.get(GLProfile.GL2);
+ Assert.assertNotNull(glp);
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+
+ GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, false, false);
+
+ System.out.println("Create Window 1");
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+ Window window = NewtFactory.createWindow(screen, caps2);
+ Assert.assertNotNull(window);
+ window.setSize(width, height);
+ GLWindow glWindow = GLWindow.create(window);
+ Assert.assertNotNull(glWindow);
+ try {
+ glWindow.setVisible(true);
+ } catch (Throwable t) {
+ // stop test and ignore if pixmap cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+
+ GLWindow windowOnScreen = null;
+ WindowListener wl=null;
+ MouseListener ml=null;
+ SurfaceUpdatedListener ul=null;
+
+ GLEventListener demo = new RedSquare();
+ Assert.assertNotNull(demo);
+
+ try {
+ WindowUtilNEWT.run(glWindow, demo, windowOnScreen, wl, ml, ul, 2, true /*snapshot*/, false /*debug*/);
+ } catch (Throwable t) {
+ // stop test and ignore if pixmap cannot be used
+ t.printStackTrace();
+ Assume.assumeNoException(t);
+ }
+
+ if(null!=windowOnScreen) {
+ windowOnScreen.destroy();
+ }
+ if(null!=glWindow) {
+ glWindow.destroy();
+ }
+ if(null!=window) {
+ window.destroy();
+ }
+ if(null!=screen) {
+ screen.destroy();
+ }
+ if(null!=display) {
+ display.destroy();
+ }
+ }
+ public static void main(String args[]) throws IOException {
+ String tstname = TestOffscreen01NEWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/WindowUtilNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/WindowUtilNEWT.java
new file mode 100644
index 000000000..ba9896d4b
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/WindowUtilNEWT.java
@@ -0,0 +1,110 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.offscreen;
+
+import com.jogamp.opengl.test.junit.util.*;
+
+import org.junit.Assert;
+
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+
+public class WindowUtilNEWT {
+
+ public static GLCapabilities fixCaps(GLCapabilities caps, boolean onscreen, boolean pbuffer, boolean undecorated) {
+ GLCapabilities caps2 = (GLCapabilities) caps.cloneMutable();
+ caps2.setOnscreen(onscreen);
+ caps2.setPBuffer(!onscreen && pbuffer);
+ caps2.setDoubleBuffered(!onscreen);
+ return caps2;
+ }
+
+ public static void setDemoFields(GLEventListener demo, Window window, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(window);
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ public static void run(GLWindow windowOffScreen, GLEventListener demo,
+ GLWindow windowOnScreen, WindowListener wl, MouseListener ml,
+ SurfaceUpdatedListener ul, int frames, boolean snapshot, boolean debug) {
+ Assert.assertNotNull(windowOffScreen);
+ Assert.assertNotNull(demo);
+
+ setDemoFields(demo, windowOffScreen, windowOffScreen, debug);
+ windowOffScreen.addGLEventListener(demo);
+
+ if ( null != windowOnScreen ) {
+ if(null!=wl) {
+ windowOnScreen.addWindowListener(wl);
+ }
+ if(null!=ml) {
+ windowOnScreen.addMouseListener(ml);
+ }
+ windowOnScreen.setVisible(true);
+ }
+
+ GLDrawable readDrawable = windowOffScreen.getContext().getGLDrawable() ;
+
+ if ( null == windowOnScreen ) {
+ if(snapshot) {
+ Surface2File s2f = new Surface2File();
+ windowOffScreen.addSurfaceUpdatedListener(s2f);
+ }
+ } else {
+ ReadBuffer2Screen readDemo = new ReadBuffer2Screen( readDrawable ) ;
+ windowOnScreen.addGLEventListener(readDemo);
+ }
+ if(null!=ul) {
+ windowOffScreen.addSurfaceUpdatedListener(ul);
+ }
+
+ if(debug) {
+ System.out.println("+++++++++++++++++++++++++++");
+ System.out.println(windowOffScreen);
+ System.out.println("+++++++++++++++++++++++++++");
+ }
+
+ while ( windowOffScreen.getTotalFrames() < frames) {
+ windowOffScreen.display();
+ }
+ windowOffScreen.removeAllSurfaceUpdatedListener();
+
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/texture/TestTexture01AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/texture/TestTexture01AWT.java
new file mode 100644
index 000000000..bd83799d4
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/texture/TestTexture01AWT.java
@@ -0,0 +1,146 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.texture;
+
+import com.jogamp.opengl.test.junit.jogl.util.texture.gl2.TextureGL2ListenerDraw1;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.awt.GLCanvas;
+import com.jogamp.opengl.util.texture.TextureData;
+import com.jogamp.opengl.util.texture.awt.AWTTextureIO;
+import com.jogamp.opengl.util.Animator;
+
+import java.awt.AlphaComposite;
+import java.awt.Color;
+import java.awt.Frame;
+import java.awt.GradientPaint;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+
+import java.io.IOException;
+import org.junit.Assert;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestTexture01AWT extends UITestCase {
+ static GLProfile glp;
+ static GLCapabilities caps;
+ BufferedImage textureImage;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ glp = GLProfile.get(GLProfile.GL2GL3);
+ Assert.assertNotNull(glp);
+ caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ }
+
+ @Before
+ public void initTest() {
+ // create base image
+ BufferedImage baseImage = new BufferedImage(256, 256, BufferedImage.TYPE_3BYTE_BGR);
+ Assert.assertNotNull(baseImage);
+ Graphics2D g = baseImage.createGraphics();
+ Assert.assertNotNull(g);
+ g.setPaint(new GradientPaint(0, 0, Color.CYAN,
+ baseImage.getWidth(), baseImage.getHeight(), Color.BLUE));
+ g.fillRect(0, 0, baseImage.getWidth(), baseImage.getHeight());
+ g.dispose();
+
+ // create texture image
+ int imageType = BufferedImage.TYPE_3BYTE_BGR;
+ textureImage = new BufferedImage(baseImage.getWidth(),
+ baseImage.getHeight(),
+ imageType);
+ Assert.assertNotNull(textureImage);
+ g = textureImage.createGraphics();
+ g.setComposite(AlphaComposite.Src);
+ g.drawImage(baseImage, 0, 0, null);
+ g.dispose();
+
+ baseImage.flush();
+ baseImage=null;
+ }
+
+ @After
+ public void cleanupTest() {
+ Assert.assertNotNull(textureImage);
+ textureImage.flush();
+ textureImage=null;
+ }
+
+ @Test
+ public void test1() throws InterruptedException {
+ GLCanvas glCanvas = new GLCanvas(caps);
+
+ Frame frame = new Frame("Texture Test");
+ Assert.assertNotNull(frame);
+ frame.add(glCanvas);
+ frame.setSize(512, 512);
+
+ // create texture
+ TextureData textureData = AWTTextureIO.newTextureData(caps.getGLProfile(), textureImage, false);
+ glCanvas.addGLEventListener(new TextureGL2ListenerDraw1(textureData));
+
+ Animator animator = new Animator(glCanvas);
+ frame.setVisible(true);
+ animator.start();
+
+ Thread.sleep(500); // 500 ms
+
+ animator.stop();
+ frame.setVisible(false);
+ frame.remove(glCanvas);
+ glCanvas=null;
+ Assert.assertNotNull(frame);
+ frame.dispose();
+ frame=null;
+ }
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestTexture01AWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java
new file mode 100644
index 000000000..b41dde645
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java
@@ -0,0 +1,109 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.util.texture.gl2;
+
+import com.jogamp.opengl.util.texture.Texture;
+import com.jogamp.opengl.util.texture.TextureCoords;
+import com.jogamp.opengl.util.texture.TextureData;
+import com.jogamp.opengl.util.texture.TextureIO;
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2ES1;
+import javax.media.opengl.GL2;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.glu.GLU;
+
+public class TextureGL2ListenerDraw1 implements GLEventListener {
+ private GLU glu = new GLU();
+ private TextureData textureData;
+ private Texture texture;
+
+ public TextureGL2ListenerDraw1(TextureData td) {
+ this.textureData = td;
+ }
+
+ public void init(GLAutoDrawable drawable) {
+ if(null!=textureData) {
+ this.texture = TextureIO.newTexture(textureData);
+ }
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ GL2 gl = drawable.getGL().getGL2();
+ gl.glMatrixMode(GL2ES1.GL_PROJECTION);
+ gl.glLoadIdentity();
+ glu.gluOrtho2D(0, 1, 0, 1);
+ gl.glMatrixMode(GL2ES1.GL_MODELVIEW);
+ gl.glLoadIdentity();
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ GL2 gl = drawable.getGL().getGL2();
+ if(null!=texture) {
+ texture.disable();
+ texture.destroy(gl);
+ }
+ if(null!=textureData) {
+ textureData.destroy();
+ }
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ GL2 gl = drawable.getGL().getGL2();
+
+ // need a valid GL context for this ..
+
+ /** OpenGL ..
+ texture.updateSubImage(textureData, 0,
+ 20, 20,
+ 20, 20,
+ 100, 100); */
+
+
+ // Now draw one quad with the texture
+ if(null!=texture) {
+ texture.enable();
+ texture.bind();
+ gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE);
+ TextureCoords coords = texture.getImageTexCoords();
+ gl.glBegin(GL2.GL_QUADS);
+ gl.glTexCoord2f(coords.left(), coords.bottom());
+ gl.glVertex3f(0, 0, 0);
+ gl.glTexCoord2f(coords.right(), coords.bottom());
+ gl.glVertex3f(1, 0, 0);
+ gl.glTexCoord2f(coords.right(), coords.top());
+ gl.glVertex3f(1, 1, 0);
+ gl.glTexCoord2f(coords.left(), coords.top());
+ gl.glVertex3f(0, 1, 0);
+ gl.glEnd();
+ texture.disable();
+ }
+ }
+}
+
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java
new file mode 100644
index 000000000..8cad4f0ed
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java
@@ -0,0 +1,141 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt;
+
+import org.junit.Test;
+
+import java.lang.reflect.InvocationTargetException;
+import java.awt.EventQueue;
+import java.awt.Toolkit;
+import javax.swing.JFrame;
+import javax.swing.SwingUtilities;
+
+import javax.media.nativewindow.NativeWindow;
+import javax.media.nativewindow.util.Point;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+import com.jogamp.newt.Window;
+import com.jogamp.newt.awt.NewtCanvasAWT;
+import com.jogamp.newt.event.WindowAdapter;
+import com.jogamp.newt.event.WindowEvent;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+public class TestCloseNewtAWT extends UITestCase {
+
+ GLWindow newtWindow = null;
+ NewtCanvasAWT newtCanvas = null;
+ JFrame frame = null;
+
+ class MyCanvas extends NewtCanvasAWT {
+ public MyCanvas(Window window) {
+ super(window);
+ }
+
+ public void addNotify() {
+ System.err.println("MyCanvas START add: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock()));
+ super.addNotify();
+ System.err.println("MyCanvas END add: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock()));
+ }
+
+ public void removeNotify() {
+ System.err.println("MyCanvas START remove: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock()));
+
+ // trigger critical situation around the AWT TreeLock
+ newtWindow.runOnEDTIfAvail(true, new Runnable() {
+ public void run() {
+ // NEWT EDT while AWT is locked
+ System.err.println("MyCanvas On NEWT-EDT From AWT-EDT: "+Thread.currentThread()+
+ ", holds AWTTreeLock: "+Thread.holdsLock(MyCanvas.this.getTreeLock()));
+
+ // Critical: Within NEWT EDT, while AWT is locked
+ NativeWindow nw = MyCanvas.this.getNativeWindow();
+ if(null != nw) {
+ Point p = nw.getLocationOnScreen(null);
+ System.err.println("MyCanvas On NEWT-EDT: position: "+p);
+ } else {
+ System.err.println("MyCanvas On NEWT-EDT: position n/a, null NativeWindow");
+ }
+ }
+ });
+ System.err.println("MyCanvas passed critical: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock()));
+
+ super.removeNotify();
+
+ System.err.println("MyCanvas END remove: "+Thread.currentThread()+", holds AWTTreeLock: "+Thread.holdsLock(this.getTreeLock()));
+ }
+ }
+
+ class NEWTWindowClosingAdapter extends WindowAdapter {
+ public void windowDestroyNotify(WindowEvent e) {
+ System.err.println("Destroy NEWT: windowDestroyNotify "+Thread.currentThread() + ", "+ e);
+ }
+ }
+
+ class AWTClosingWindowAdapter extends java.awt.event.WindowAdapter {
+ public void windowClosing(WindowEvent ev) {
+ System.err.println("Destroy AWT: windowClosing "+Thread.currentThread() + ", "+ ev);
+ }
+ }
+
+
+ @Test
+ public void testCloseNewtAWT() throws InterruptedException, InvocationTargetException {
+ newtWindow = GLWindow.create(new GLCapabilities(GLProfile.getDefault()));
+ newtWindow.addWindowListener(new NEWTWindowClosingAdapter());
+ newtCanvas = new MyCanvas(newtWindow);
+
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ frame = new JFrame("NEWT Close Test");
+ frame.addWindowListener(new AWTClosingWindowAdapter());
+ frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+ frame.getContentPane().add(newtCanvas);
+ frame.pack();
+ frame.setSize(800, 600);
+ frame.setVisible(true);
+ }
+ });
+ Thread.sleep(1000);
+
+ // programatically issue windowClosing
+ Toolkit tk = Toolkit.getDefaultToolkit();
+ EventQueue evtQ = tk.getSystemEventQueue();
+ evtQ.postEvent(new java.awt.event.WindowEvent(frame, java.awt.event.WindowEvent.WINDOW_CLOSING));
+ Thread.sleep(200);
+
+ GLProfile.shutdown();
+ }
+
+ public static void main(String[] args) {
+ String tstname = TestCloseNewtAWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle01NEWT.java
new file mode 100644
index 000000000..9343e2dd8
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle01NEWT.java
@@ -0,0 +1,264 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import javax.media.nativewindow.*;
+import javax.media.opengl.*;
+
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import java.io.IOException;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestDisplayLifecycle01NEWT extends UITestCase {
+ static GLProfile glp;
+ static GLCapabilities caps;
+ static int width, height;
+ static long durationPerTest = 100; // ms
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ glp = GLProfile.getDefault();
+ caps = new GLCapabilities(glp);
+ }
+
+ static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height)
+ throws InterruptedException
+ {
+ Assert.assertNotNull(caps);
+
+ //
+ // Create native windowing resources .. X11/Win/OSX
+ //
+ GLWindow glWindow;
+ if(null!=screen) {
+ Window window = NewtFactory.createWindow(screen, caps);
+ Assert.assertNotNull(window);
+ glWindow = GLWindow.create(window);
+ } else {
+ glWindow = GLWindow.create(caps);
+ }
+
+ GLEventListener demo = new Gears();
+ setDemoFields(demo, glWindow);
+ glWindow.addGLEventListener(demo);
+ glWindow.addWindowListener(new TraceWindowAdapter());
+ glWindow.setSize(width, height);
+ return glWindow;
+ }
+
+ private void testDisplayCreate01(Display display, Screen screen) throws InterruptedException {
+ // start-state == end-state
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(false,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+
+ // Create Window, pending lazy native creation
+ GLWindow window = createWindow(screen, caps, width, height);
+ Assert.assertEquals(screen,window.getScreen());
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+
+ Assert.assertNotNull(window.getScreen());
+ Assert.assertEquals(true,window.isValid());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ // lazy native creation sequence: Display, Screen and Window
+ Assert.assertEquals(0, window.getTotalFrames());
+ window.setVisible(true);
+
+ Assert.assertEquals(screen,window.getScreen());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(1,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+ System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames());
+ Assert.assertTrue(0 < window.getTotalFrames());
+
+ while(window.getDuration()<1*durationPerTest) {
+ window.display();
+ Thread.sleep(100);
+ }
+ System.err.println("duration: "+window.getDuration());
+
+ // just make the Window invisible
+ window.setVisible(false);
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ // just make the Window visible again
+ window.resetCounter();
+ Assert.assertEquals(0, window.getTotalFrames());
+ window.setVisible(true);
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+ System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames());
+ Assert.assertTrue(0 < window.getTotalFrames());
+
+ while(window.getDuration()<2*durationPerTest) {
+ window.display();
+ Thread.sleep(100);
+ }
+ System.err.println("duration: "+window.getDuration());
+
+ // destruction ..
+ window.destroy();
+ Assert.assertEquals(screen,window.getScreen());
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(false,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(true, window.isValid());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+ window.resetCounter();
+ Assert.assertEquals(0, window.getTotalFrames());
+
+ // a display call shall not change a thing
+ window.display();
+ Assert.assertEquals(0, window.getTotalFrames());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ // recover Window
+ window.setVisible(true);
+
+ Assert.assertEquals(screen,window.getScreen());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(1,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+ System.err.println("Frames for setVisible(true) 2: "+window.getTotalFrames());
+ Assert.assertTrue(0 < window.getTotalFrames());
+
+ while(window.getDuration()<1*durationPerTest) {
+ window.display();
+ Thread.sleep(100);
+ }
+ System.err.println("duration: "+window.getDuration());
+
+ // destruction ..
+ window.destroy();
+ display.dumpDisplayList("Post destroy(true)");
+
+ // end-state == start-state
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(false,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+
+ Assert.assertNotNull(window.getScreen());
+ Assert.assertEquals(true,window.isValid());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+ }
+
+ @Test
+ public void testDisplayCreate01_AutoDestroyLifecycle() throws InterruptedException {
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ // Create Display/Screen, pending lazy native creation
+ Display display = NewtFactory.createDisplay(null);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ testDisplayCreate01(display, screen);
+ testDisplayCreate01(display, screen);
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ if(!MiscUtils.setFieldIfExists(demo, "window", glWindow)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ System.err.println("durationPerTest: "+durationPerTest);
+ String tstname = TestDisplayLifecycle01NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle02NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle02NEWT.java
new file mode 100644
index 000000000..d17c5f025
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle02NEWT.java
@@ -0,0 +1,386 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import javax.media.nativewindow.*;
+import javax.media.opengl.*;
+
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import java.io.IOException;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestDisplayLifecycle02NEWT extends UITestCase {
+ static GLProfile glp;
+ static GLCapabilities caps;
+ static int width, height;
+ static long durationPerTest = 100; // ms
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ glp = GLProfile.getDefault();
+ caps = new GLCapabilities(glp);
+ }
+
+ static GLWindow createWindow(GLCapabilities caps, int width, int height)
+ throws InterruptedException
+ {
+ Assert.assertNotNull(caps);
+
+ //
+ // Create native windowing resources .. X11/Win/OSX
+ //
+ GLWindow glWindow = GLWindow.create(caps);
+
+ GLEventListener demo = new Gears();
+ setDemoFields(demo, glWindow);
+ glWindow.addGLEventListener(demo);
+ glWindow.addWindowListener(new TraceWindowAdapter());
+ glWindow.setSize(width, height);
+ return glWindow;
+ }
+
+ private void testDisplayCreate01Impl() throws InterruptedException {
+ // start-state == end-state
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ // Create Window, pending lazy native creation
+ GLWindow window = createWindow(caps, width, height);
+ Screen screen = window.getScreen();
+ Display display = screen.getDisplay();
+
+ Assert.assertEquals(screen,window.getScreen());
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,Screen.getActiveScreenNumber());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ // lazy native creation sequence: Display, Screen and Window
+ Assert.assertEquals(0, window.getTotalFrames());
+ window.setVisible(true);
+
+ Assert.assertEquals(screen,window.getScreen());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(1,Screen.getActiveScreenNumber());
+ Assert.assertEquals(1,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+ System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames());
+ Assert.assertTrue(0 < window.getTotalFrames());
+
+ while(window.getDuration()<1*durationPerTest) {
+ window.display();
+ Thread.sleep(100);
+ }
+ System.err.println("duration: "+window.getDuration());
+
+ // just make the Window invisible
+ window.setVisible(false);
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ // just make the Window visible again
+ window.resetCounter();
+ Assert.assertEquals(0, window.getTotalFrames());
+ window.setVisible(true);
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+ System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames());
+ Assert.assertTrue(0 < window.getTotalFrames());
+
+ while(window.getDuration()<2*durationPerTest) {
+ window.display();
+ Thread.sleep(100);
+ }
+ System.err.println("duration: "+window.getDuration());
+
+ // destruction.. ref count down, but keep all
+ window.destroy();
+ Assert.assertEquals(screen,window.getScreen());
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(false,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,Screen.getActiveScreenNumber());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertNotNull(window.getScreen());
+ Assert.assertEquals(true,window.isValid());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ window.resetCounter();
+ Assert.assertEquals(0, window.getTotalFrames());
+
+ // a display call shall not change a thing
+ window.display();
+ Assert.assertEquals(0, window.getTotalFrames());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ // recover Window
+ window.setVisible(true);
+
+ Assert.assertEquals(screen,window.getScreen());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,window.isValid());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(1,Screen.getActiveScreenNumber());
+ Assert.assertEquals(1,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+ System.err.println("Frames for setVisible(true) 2: "+window.getTotalFrames());
+ Assert.assertTrue(0 < window.getTotalFrames());
+
+ while(window.getDuration()<1*durationPerTest) {
+ window.display();
+ Thread.sleep(100);
+ }
+ System.err.println("duration: "+window.getDuration());
+
+ // destruction + invalidate, ie Display/Screen will be unreferenced
+ window.invalidate();
+ Assert.assertNull(window.getScreen());
+ Assert.assertEquals(false,window.isValid());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ display.dumpDisplayList("Post destroy(true)");
+
+ // end-state == start-state
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(false,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,Screen.getActiveScreenNumber());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+ }
+
+ @Test
+ public void testDisplayCreate01() throws InterruptedException {
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ // Create Display/Screen, pending lazy native creation
+ testDisplayCreate01Impl();
+ testDisplayCreate01Impl();
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ }
+
+ private void testDisplayCreate02Impl() throws InterruptedException {
+ // start-state == end-state
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ // Create Window, pending lazy native creation
+ GLWindow window1 = createWindow(caps, width, height);
+ window1.setPosition(0, 0);
+ Screen screen = window1.getScreen();
+ Display display = screen.getDisplay();
+
+ GLWindow window2 = createWindow(caps, width, height);
+ Assert.assertSame(screen, window2.getScreen());
+ Assert.assertSame(display, window2.getScreen().getDisplay());
+ window2.setPosition(screen.getWidth()-width, 0);
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,Screen.getActiveScreenNumber());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(false,window1.isNativeValid());
+ Assert.assertEquals(false,window1.isVisible());
+ Assert.assertEquals(false,window2.isNativeValid());
+ Assert.assertEquals(false,window2.isVisible());
+
+ // lazy native creation sequence: Display, Screen and Window
+ Assert.assertEquals(0, window1.getTotalFrames());
+ window1.setVisible(true);
+
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(1,Screen.getActiveScreenNumber());
+ Assert.assertEquals(1,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(true,window1.isNativeValid());
+ Assert.assertEquals(true,window1.isVisible());
+ System.err.println("Frames for setVisible(true) 1: "+window1.getTotalFrames());
+ Assert.assertTrue(0 < window1.getTotalFrames());
+
+ Assert.assertEquals(0, window2.getTotalFrames());
+ window2.setVisible(true);
+
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(1,Screen.getActiveScreenNumber());
+ Assert.assertEquals(2,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(true,window2.isNativeValid());
+ Assert.assertEquals(true,window2.isVisible());
+ System.err.println("Frames for setVisible(true) 2: "+window2.getTotalFrames());
+ Assert.assertTrue(0 < window2.getTotalFrames());
+
+ while(window1.getDuration()<1*durationPerTest) {
+ window1.display();
+ Thread.sleep(100);
+ }
+ System.err.println("duration: "+window1.getDuration());
+
+ // just make the Window invisible
+ window1.setVisible(false);
+ Assert.assertEquals(true,window1.isNativeValid());
+ Assert.assertEquals(false,window1.isVisible());
+
+ // destruction ...
+ window1.destroy();
+ Assert.assertNotNull(window1.getScreen());
+ Assert.assertEquals(true,window1.isValid());
+ Assert.assertEquals(false,window1.isNativeValid());
+ Assert.assertEquals(false,window1.isVisible());
+
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(1,Screen.getActiveScreenNumber());
+ Assert.assertEquals(1,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+
+ // destruction
+ window2.destroy();
+ Assert.assertNotNull(window2.getScreen());
+ Assert.assertEquals(true,window2.isValid());
+ Assert.assertEquals(false,window2.isNativeValid());
+ Assert.assertEquals(false,window2.isVisible());
+
+ // end-state == start-state
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(false,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,Screen.getActiveScreenNumber());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+
+ // invalidate .. remove all refs
+ window1.invalidate();
+ Assert.assertNull(window1.getScreen());
+ Assert.assertEquals(false,window1.isValid());
+ Assert.assertEquals(false,window1.isNativeValid());
+ Assert.assertEquals(false,window1.isVisible());
+
+ // invalidate .. remove all refs
+ window2.invalidate();
+ Assert.assertNull(window2.getScreen());
+ Assert.assertEquals(false,window2.isValid());
+ Assert.assertEquals(false,window2.isNativeValid());
+ Assert.assertEquals(false,window2.isVisible());
+
+ }
+
+ @Test
+ public void testDisplayCreate02() throws InterruptedException {
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ // Create Display/Screen, pending lazy native creation
+ testDisplayCreate02Impl();
+ testDisplayCreate02Impl();
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ if(!MiscUtils.setFieldIfExists(demo, "window", glWindow)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ System.err.println("durationPerTest: "+durationPerTest);
+ String tstname = TestDisplayLifecycle02NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestEventSourceNotAWTBug.java b/src/test/com/jogamp/opengl/test/junit/newt/TestEventSourceNotAWTBug.java
new file mode 100644
index 000000000..67dd2a33c
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestEventSourceNotAWTBug.java
@@ -0,0 +1,110 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+import javax.swing.JFrame;
+import javax.swing.SwingUtilities;
+import javax.swing.WindowConstants;
+
+import com.jogamp.newt.awt.NewtCanvasAWT;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+import com.jogamp.opengl.test.junit.util.*;
+
+/**
+ * This simple program will throw a {@link RuntimeException} when the application is closed.
+ */
+public class TestEventSourceNotAWTBug extends UITestCase {
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ }
+
+ @Test
+ public void testEventSourceNotNewtBug() throws InterruptedException {
+ JFrame jf = new JFrame();
+
+ jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+
+ final GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
+ final GLWindow glWindow = GLWindow.create(caps);
+ final NewtCanvasAWT canvas = new NewtCanvasAWT(glWindow);
+ jf.getContentPane().add(canvas);
+
+ // The following line isn't event necessary to see the problem.
+ glWindow.addGLEventListener(new Gears());
+
+ final JFrame f_jf = jf;
+
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ f_jf.setSize(800, 600);
+ f_jf.setVisible(true);
+ }
+ });
+
+ Thread.sleep(500);
+
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ f_jf.dispose();
+ }
+ });
+ glWindow.invalidate();
+ }
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestEventSourceNotAWTBug.class.getName();
+ /*
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); */
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java
new file mode 100644
index 000000000..047df5cf7
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java
@@ -0,0 +1,201 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt;
+
+import org.junit.Assert;
+import org.junit.AfterClass;
+
+import java.awt.AWTException;
+import java.awt.BorderLayout;
+import java.awt.Button;
+import java.awt.Robot;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLProfile;
+import javax.swing.JFrame;
+
+import java.util.ArrayList;
+import java.io.IOException;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.jogamp.newt.awt.NewtCanvasAWT;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquare;
+
+import com.jogamp.opengl.test.junit.util.*;
+
+public class TestFocus01SwingAWTRobot extends UITestCase {
+ static int width, height;
+ static long durationPerTest = 800;
+ static long awtWaitTimeout = 1000;
+
+ static GLCapabilities glCaps;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ glCaps = new GLCapabilities(null);
+ }
+
+ @AfterClass
+ public static void release() {
+ }
+
+ @Test
+ public void testFocus01ProgrFocus() throws AWTException, InterruptedException, InvocationTargetException {
+ testFocus01ProgrFocusImpl(null);
+ }
+
+ @Test
+ public void testFocus02RobotFocus() throws AWTException, InterruptedException, InvocationTargetException {
+ Robot robot = new Robot();
+ robot.setAutoWaitForIdle(true);
+ testFocus01ProgrFocusImpl(robot);
+ }
+
+ private void testFocus01ProgrFocusImpl(Robot robot) throws AWTException,
+ InvocationTargetException, InterruptedException {
+ ArrayList eventCountAdapters = new ArrayList();
+
+ // Create a window.
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ glWindow1.setTitle("testNewtChildFocus");
+ GLEventListener demo1 = new RedSquare();
+ TestListenerCom01AWT.setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+ NEWTFocusAdapter glWindow1FA = new NEWTFocusAdapter("GLWindow1");
+ eventCountAdapters.add(glWindow1FA);
+ glWindow1.addWindowListener(glWindow1FA);
+
+ // Monitor NEWT focus and keyboard events.
+ NEWTKeyAdapter glWindow1KA = new NEWTKeyAdapter("GLWindow1");
+ eventCountAdapters.add(glWindow1KA);
+ glWindow1.addKeyListener(glWindow1KA);
+
+ // Wrap the window in a canvas.
+ final NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+
+ // Monitor AWT focus and keyboard events.
+ AWTKeyAdapter newtCanvasAWTKA = new AWTKeyAdapter("NewtCanvasAWT");
+ newtCanvasAWT.addKeyListener(newtCanvasAWTKA);
+ eventCountAdapters.add(newtCanvasAWTKA);
+ AWTFocusAdapter newtCanvasAWTFA = new AWTFocusAdapter("NewtCanvasAWT");
+ newtCanvasAWT.addFocusListener(newtCanvasAWTFA);
+ eventCountAdapters.add(newtCanvasAWTFA);
+
+ // Add the canvas to a frame, and make it all visible.
+ JFrame frame1 = new JFrame("Swing AWT Parent Frame: "
+ + glWindow1.getTitle());
+ frame1.getContentPane().add(newtCanvasAWT, BorderLayout.CENTER);
+ Button button = new Button("Click me ..");
+ AWTFocusAdapter buttonFA = new AWTFocusAdapter("Button");
+ button.addFocusListener(buttonFA);
+ eventCountAdapters.add(buttonFA);
+ AWTKeyAdapter buttonKA = new AWTKeyAdapter("Button");
+ button.addKeyListener(buttonKA);
+ eventCountAdapters.add(buttonKA);
+ frame1.getContentPane().add(button, BorderLayout.NORTH);
+ frame1.setSize(width, height);
+ frame1.setVisible(true);
+ Assert.assertTrue(AWTRobotUtil.toFront(robot, frame1));
+
+ int wait=0;
+ while(wait<awtWaitTimeout/100 && glWindow1.getTotalFrames()<1) { Thread.sleep(awtWaitTimeout/10); wait++; }
+ System.err.println("Frames for initial setVisible(true): "+glWindow1.getTotalFrames());
+ Assert.assertTrue(glWindow1.isVisible());
+ Assert.assertTrue(0 < glWindow1.getTotalFrames());
+
+ // Continuous animation ..
+ Animator animator = new Animator(glWindow1);
+ animator.start();
+
+ // Button Focus
+ Thread.sleep(100); // allow event sync
+ System.err.println("FOCUS AWT Button request");
+ EventCountAdapterUtil.reset(eventCountAdapters);
+ Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, button, button, buttonFA, null));
+ Assert.assertEquals(1, buttonFA.getCount());
+ Assert.assertEquals(0, glWindow1FA.getCount());
+ Assert.assertEquals(0, newtCanvasAWTFA.getCount());
+ System.err.println("FOCUS AWT Button sync");
+ Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, button, buttonKA));
+
+ // Request the AWT focus, which should automatically provide the NEWT window with focus.
+ Thread.sleep(100); // allow event sync
+ System.err.println("FOCUS NEWT Canvas/GLWindow request");
+ EventCountAdapterUtil.reset(eventCountAdapters);
+ Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild(), glWindow1FA, buttonFA));
+ Assert.assertTrue(AWTRobotUtil.waitForCount(0, newtCanvasAWTFA));
+ Assert.assertEquals(1, glWindow1FA.getCount());
+ Assert.assertEquals(0, newtCanvasAWTFA.getCount());
+ Assert.assertEquals(-1, buttonFA.getCount()); // lost focus
+ System.err.println("FOCUS NEWT Canvas/GLWindow sync");
+ Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, glWindow1, glWindow1KA));
+ Assert.assertEquals("AWT parent canvas received keyboard events", 0, newtCanvasAWTKA.getCount());
+
+ // Remove listeners to avoid logging during dispose/destroy.
+ glWindow1.removeKeyListener(glWindow1KA);
+ glWindow1.removeWindowListener(glWindow1FA);
+ newtCanvasAWT.removeKeyListener(newtCanvasAWTKA);
+ newtCanvasAWT.removeFocusListener(newtCanvasAWTFA);
+
+ // Shutdown the test.
+ animator.stop();
+ frame1.dispose();
+ glWindow1.invalidate();
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ System.out.println("durationPerTest: "+durationPerTest);
+ String tstname = TestFocus01SwingAWTRobot.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java
new file mode 100644
index 000000000..15e4c3ad8
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java
@@ -0,0 +1,301 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt;
+
+import java.lang.reflect.*;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import java.awt.AWTException;
+import java.awt.Button;
+import java.awt.BorderLayout;
+import java.awt.Container;
+import java.awt.Robot;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
+import java.util.ArrayList;
+
+import javax.media.opengl.*;
+
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.newt.opengl.*;
+import com.jogamp.newt.awt.NewtCanvasAWT;
+
+import java.io.IOException;
+
+import com.jogamp.opengl.test.junit.util.*;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestFocus02SwingAWTRobot extends UITestCase {
+ static int width, height;
+ static long durationPerTest = 800;
+ static long awtWaitTimeout = 1000;
+ static long waitReparent = 0;
+ static GLCapabilities glCaps;
+
+ @BeforeClass
+ public static void initClass() throws AWTException {
+ width = 640;
+ height = 480;
+
+ JFrame f = new JFrame();
+ f.setSize(100,100);
+ f.setVisible(true);
+ f.dispose();
+ f=null;
+
+ GLProfile.initSingleton(false);
+ glCaps = new GLCapabilities(null);
+ }
+
+ @AfterClass
+ public static void release() {
+ }
+
+ private void testFocus01ProgrFocusImpl(Robot robot)
+ throws AWTException, InterruptedException, InvocationTargetException {
+ int x = 0;
+ int y = 0;
+
+ ArrayList eventCountAdapters = new ArrayList();
+
+ /**
+ * JFrame . JPanel . Container . NewtCanvasAWT . GLWindow
+ */
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy");
+ GLEventListener demo1 = new Gears();
+ glWindow1.addGLEventListener(demo1);
+ NEWTFocusAdapter glWindow1FA = new NEWTFocusAdapter("GLWindow1");
+ glWindow1.addWindowListener(glWindow1FA);
+ eventCountAdapters.add(glWindow1FA);
+ NEWTKeyAdapter glWindow1KA = new NEWTKeyAdapter("GLWindow1");
+ glWindow1.addKeyListener(glWindow1KA);
+ eventCountAdapters.add(glWindow1KA);
+ NEWTMouseAdapter glWindow1MA = new NEWTMouseAdapter("GLWindow1");
+ glWindow1.addMouseListener(glWindow1MA);
+ eventCountAdapters.add(glWindow1MA);
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+ AWTFocusAdapter newtCanvasAWTFA = new AWTFocusAdapter("NewtCanvasAWT");
+ newtCanvasAWT.addFocusListener(newtCanvasAWTFA);
+ eventCountAdapters.add(newtCanvasAWTFA);
+ AWTKeyAdapter newtCanvasAWTKA = new AWTKeyAdapter("NewtCanvasAWT");
+ newtCanvasAWT.addKeyListener(newtCanvasAWTKA);
+ eventCountAdapters.add(newtCanvasAWTKA);
+ AWTMouseAdapter newtCanvasAWTMA = new AWTMouseAdapter("NewtCanvasAWT");
+ newtCanvasAWT.addMouseListener(newtCanvasAWTMA);
+ eventCountAdapters.add(newtCanvasAWTMA);
+
+ Button buttonNorthInner = new Button("north");
+ AWTFocusAdapter buttonNorthInnerFA = new AWTFocusAdapter("ButtonNorthInner");
+ buttonNorthInner.addFocusListener(buttonNorthInnerFA);
+ eventCountAdapters.add(buttonNorthInnerFA);
+ AWTKeyAdapter buttonNorthInnerKA = new AWTKeyAdapter("ButtonNorthInner");
+ buttonNorthInner.addKeyListener(buttonNorthInnerKA);
+ eventCountAdapters.add(buttonNorthInnerKA);
+ AWTMouseAdapter buttonNorthInnerMA = new AWTMouseAdapter("ButtonNorthInner");
+ buttonNorthInner.addMouseListener(buttonNorthInnerMA);
+ eventCountAdapters.add(buttonNorthInnerMA);
+ Container container1 = new Container();
+ container1.setLayout(new BorderLayout());
+ container1.add(buttonNorthInner, BorderLayout.NORTH);
+ container1.add(new Button("south"), BorderLayout.SOUTH);
+ container1.add(new Button("east"), BorderLayout.EAST);
+ container1.add(new Button("west"), BorderLayout.WEST);
+ container1.add(newtCanvasAWT, BorderLayout.CENTER);
+
+ Button buttonNorthOuter = new Button("north");
+ AWTFocusAdapter buttonNorthOuterFA = new AWTFocusAdapter("ButtonNorthOuter");
+ buttonNorthOuter.addFocusListener(buttonNorthOuterFA);
+ eventCountAdapters.add(buttonNorthOuterFA);
+ AWTKeyAdapter buttonNorthOuterKA = new AWTKeyAdapter("ButtonNorthOuter");
+ buttonNorthOuter.addKeyListener(buttonNorthOuterKA);
+ eventCountAdapters.add(buttonNorthOuterKA);
+ AWTMouseAdapter buttonNorthOuterMA = new AWTMouseAdapter("ButtonNorthOuter");
+ buttonNorthOuter.addMouseListener(buttonNorthOuterMA);
+ eventCountAdapters.add(buttonNorthOuterMA);
+ JPanel jPanel1 = new JPanel();
+ jPanel1.setLayout(new BorderLayout());
+ jPanel1.add(buttonNorthOuter, BorderLayout.NORTH);
+ jPanel1.add(new Button("south"), BorderLayout.SOUTH);
+ jPanel1.add(new Button("east"), BorderLayout.EAST);
+ jPanel1.add(new Button("west"), BorderLayout.WEST);
+ jPanel1.add(container1, BorderLayout.CENTER);
+
+ JFrame jFrame1 = new JFrame("Swing Parent JFrame");
+ AWTFocusAdapter jFrame1FA = new AWTFocusAdapter("JFrame1");
+ jFrame1.addFocusListener(jFrame1FA);
+ // jFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ jFrame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event!
+ jFrame1.setContentPane(jPanel1);
+ jFrame1.setSize(width, height);
+ jFrame1.setVisible(true); // from here on, we need to run modifications on EDT
+ Assert.assertTrue(AWTRobotUtil.toFront(robot, jFrame1));
+
+ int wait=0;
+ while(wait<awtWaitTimeout/100 && glWindow1.getTotalFrames()<1) { Thread.sleep(awtWaitTimeout/10); wait++; }
+ System.err.println("Frames for initial setVisible(true): "+glWindow1.getTotalFrames());
+ Assert.assertTrue(glWindow1.isVisible());
+ Assert.assertTrue(0 < glWindow1.getTotalFrames());
+
+ // Continuous animation ..
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+
+ // Button Outer Focus
+ Thread.sleep(100); // allow event sync
+ System.err.println("FOCUS AWT Button Outer request");
+ EventCountAdapterUtil.reset(eventCountAdapters);
+ Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, buttonNorthOuter, buttonNorthOuter, buttonNorthOuterFA, null));
+ Assert.assertEquals(1, buttonNorthOuterFA.getCount());
+ Assert.assertEquals(0, glWindow1FA.getCount());
+ Assert.assertEquals(0, newtCanvasAWTFA.getCount());
+ Assert.assertEquals(0, buttonNorthInnerFA.getCount());
+ Assert.assertEquals(0, jFrame1FA.getCount());
+ System.err.println("FOCUS AWT Button Outer sync");
+ Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, buttonNorthOuter, buttonNorthOuterKA));
+ Assert.assertEquals(1, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 1,
+ buttonNorthOuter, buttonNorthOuterMA));
+ Assert.assertEquals(3, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 2,
+ buttonNorthOuter, buttonNorthOuterMA));
+
+ // NEWT Focus
+ Thread.sleep(100); // allow event sync
+ System.err.println("FOCUS NEWT Canvas/GLWindow request");
+ EventCountAdapterUtil.reset(eventCountAdapters);
+ Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild(), glWindow1FA, buttonNorthOuterFA));
+ Assert.assertTrue(AWTRobotUtil.waitForCount(0, newtCanvasAWTFA));
+ Assert.assertEquals(1, glWindow1FA.getCount());
+ Assert.assertEquals(0, newtCanvasAWTFA.getCount());
+ Assert.assertEquals(0, buttonNorthInnerFA.getCount());
+ Assert.assertEquals(-1, buttonNorthOuterFA.getCount()); // lost focus
+ Assert.assertEquals(0, jFrame1FA.getCount());
+ System.err.println("FOCUS NEWT Canvas/GLWindow sync");
+ Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, glWindow1, glWindow1KA));
+ Assert.assertEquals("AWT parent canvas received keyboard events", 0, newtCanvasAWTKA.getCount());
+ Assert.assertEquals(1, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 1,
+ glWindow1, glWindow1MA));
+ Assert.assertEquals(3, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 2,
+ glWindow1, glWindow1MA));
+ Assert.assertEquals("AWT parent canvas received mouse events", 0, newtCanvasAWTMA.getCount());
+
+ // Button Inner Focus
+ Thread.sleep(100); // allow event sync
+ System.err.println("FOCUS AWT Button request");
+ EventCountAdapterUtil.reset(eventCountAdapters);
+ Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, buttonNorthInner, buttonNorthInner, buttonNorthInnerFA, glWindow1FA));
+ Assert.assertEquals(1, buttonNorthInnerFA.getCount());
+ Assert.assertEquals(-1, glWindow1FA.getCount()); // lost focus
+ Assert.assertEquals(0, newtCanvasAWTFA.getCount());
+ Assert.assertEquals(0, buttonNorthOuterFA.getCount());
+ Assert.assertEquals(0, jFrame1FA.getCount());
+ System.err.println("FOCUS AWT Button sync");
+ Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, buttonNorthInner, buttonNorthInnerKA));
+ Assert.assertEquals(1, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 1,
+ buttonNorthInner, buttonNorthInnerMA));
+ Assert.assertEquals(3, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 2,
+ buttonNorthInner, buttonNorthInnerMA));
+
+ // NEWT Focus
+ Thread.sleep(100); // allow event sync
+ System.err.println("FOCUS NEWT Canvas/GLWindow request");
+ EventCountAdapterUtil.reset(eventCountAdapters);
+ Assert.assertTrue(AWTRobotUtil.requestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild(), glWindow1FA, buttonNorthInnerFA));
+ Assert.assertTrue(AWTRobotUtil.waitForCount(0, newtCanvasAWTFA));
+ Assert.assertEquals(1, glWindow1FA.getCount());
+ Assert.assertEquals(0, newtCanvasAWTFA.getCount());
+ Assert.assertEquals(-1, buttonNorthInnerFA.getCount()); // lost focus
+ Assert.assertEquals(0, buttonNorthOuterFA.getCount());
+ Assert.assertEquals(0, jFrame1FA.getCount());
+ System.err.println("FOCUS NEWT Canvas/GLWindow sync");
+ Assert.assertEquals(2, AWTRobotUtil.testKeyType(robot, 2, glWindow1, glWindow1KA));
+ Assert.assertEquals("AWT parent canvas received keyboard events", 0, newtCanvasAWTKA.getCount());
+ Assert.assertEquals(1, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 1,
+ glWindow1, glWindow1MA));
+ Assert.assertEquals(3, AWTRobotUtil.testMouseClick(robot, java.awt.event.InputEvent.BUTTON1_MASK, 2,
+ glWindow1, glWindow1MA));
+ Assert.assertEquals("AWT parent canvas received mouse events", 0, newtCanvasAWTMA.getCount());
+
+
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+
+ final JFrame _jFrame1 = jFrame1;
+ final JPanel _jPanel1 = jPanel1;
+ final Container _container1 = container1;
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ _jFrame1.setVisible(false);
+ _jPanel1.remove(_container1);
+ _jFrame1.dispose();
+ } });
+
+ glWindow1.invalidate();
+ }
+
+ @Test
+ public void testFocus01ProgrFocus() throws AWTException, InterruptedException, InvocationTargetException {
+ testFocus01ProgrFocusImpl(null);
+ }
+
+ @Test
+ public void testFocus02RobotFocus() throws AWTException, InterruptedException, InvocationTargetException {
+ Robot robot = new Robot();
+ robot.setAutoWaitForIdle(true);
+ testFocus01ProgrFocusImpl(robot);
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ } else if(args[i].equals("-wait")) {
+ waitReparent = atoi(args[++i]);
+ }
+ }
+ System.err.println("durationPerTest "+durationPerTest);
+ System.err.println("waitReparent "+waitReparent);
+ String tstname = TestFocus02SwingAWTRobot.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+}
+
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows00NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows00NEWT.java
new file mode 100644
index 000000000..f9571574e
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows00NEWT.java
@@ -0,0 +1,133 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.media.opengl.*;
+
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import java.io.IOException;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+import javax.media.nativewindow.AbstractGraphicsDevice;
+
+public class TestGLWindows00NEWT extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+ static long durationPerTest = 100; // ms
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ // GLProfile.initSingleton(false);
+ width = 640;
+ height = 480;
+ glp = GLProfile.getDefault();
+ }
+
+ static GLWindow createWindow(Screen screen, GLCapabilitiesImmutable caps)
+ throws InterruptedException
+ {
+ Assert.assertNotNull(caps);
+ //
+ // Create native windowing resources .. X11/Win/OSX
+ //
+ GLWindow glWindow;
+ if(null!=screen) {
+ glWindow = GLWindow.create(screen, caps);
+ Assert.assertNotNull(glWindow);
+ } else {
+ glWindow = GLWindow.create(caps);
+ Assert.assertNotNull(glWindow);
+ }
+
+ GLEventListener demo = new Gears();
+ glWindow.addGLEventListener(demo);
+
+ glWindow.setSize(512, 512);
+ glWindow.setVisible(true);
+ Assert.assertEquals(true,glWindow.isVisible());
+ Assert.assertEquals(true,glWindow.isNativeValid());
+
+ return glWindow;
+ }
+
+ static void destroyWindow(GLWindow glWindow) {
+ if(null!=glWindow) {
+ glWindow.invalidate();
+ Assert.assertEquals(false,glWindow.isNativeValid());
+ Assert.assertEquals(false,glWindow.isValid());
+ }
+ }
+
+ @Test
+ public void testWindow00() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ GLWindow window1 = createWindow(null, caps); // local
+ Assert.assertEquals(true,window1.isNativeValid());
+ Assert.assertEquals(true,window1.isVisible());
+ AbstractGraphicsDevice device1 = window1.getScreen().getDisplay().getGraphicsDevice();
+
+ System.err.println("GLProfiles window1: "+device1.getConnection()+": "+GLProfile.glAvailabilityToString(device1));
+
+ for(int state=0; state*100<durationPerTest; state++) {
+ Thread.sleep(100);
+ }
+
+ destroyWindow(window1);
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ System.out.println("durationPerTest: "+durationPerTest);
+ String tstname = TestGLWindows00NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows01NEWT.java
new file mode 100644
index 000000000..5be97714d
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows01NEWT.java
@@ -0,0 +1,384 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.media.opengl.*;
+
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import java.io.IOException;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestGLWindows01NEWT extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+ static long durationPerTest = 100; // ms
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ // GLProfile.initSingleton(false);
+ width = 640;
+ height = 480;
+ glp = GLProfile.getDefault();
+ }
+
+ static GLWindow createWindow(Screen screen, GLCapabilities caps,
+ int width, int height, boolean onscreen, boolean undecorated,
+ boolean addGLEventListenerAfterVisible)
+ throws InterruptedException
+ {
+ Assert.assertNotNull(caps);
+ caps.setOnscreen(onscreen);
+ // System.out.println("Requested: "+caps);
+
+ //
+ // Create native windowing resources .. X11/Win/OSX
+ //
+ GLWindow glWindow;
+ if(null!=screen) {
+ glWindow = GLWindow.create(screen, caps);
+ Assert.assertNotNull(glWindow);
+ } else {
+ glWindow = GLWindow.create(caps);
+ Assert.assertNotNull(glWindow);
+ }
+
+ glWindow.setUndecorated(onscreen && undecorated);
+ Assert.assertEquals(false,glWindow.isVisible());
+ Assert.assertEquals(false,glWindow.isNativeValid());
+
+ GLEventListener demo = new Gears();
+ setDemoFields(demo, glWindow);
+ if(!addGLEventListenerAfterVisible) {
+ glWindow.addGLEventListener(demo);
+ }
+ glWindow.addWindowListener(new TraceWindowAdapter());
+
+ glWindow.setSize(width, height);
+
+ Assert.assertEquals(0, glWindow.getTotalFrames());
+ glWindow.setVisible(true);
+ Assert.assertEquals(true,glWindow.isVisible());
+ Assert.assertEquals(true,glWindow.isNativeValid());
+ System.out.println("Frames for initial setVisible(true): "+glWindow.getTotalFrames());
+ Assert.assertTrue(0 < glWindow.getTotalFrames());
+
+ //
+ // Create native OpenGL resources .. XGL/WGL/CGL ..
+ // equivalent to GLAutoDrawable methods: setVisible(true)
+ //
+ GLCapabilitiesImmutable caps2 = glWindow.getChosenGLCapabilities();
+ Assert.assertNotNull(caps2);
+ Assert.assertTrue(caps2.getGreenBits()>=5);
+ Assert.assertTrue(caps2.getBlueBits()>=5);
+ Assert.assertTrue(caps2.getRedBits()>=5);
+ Assert.assertEquals(caps2.isOnscreen(),onscreen);
+
+ if(addGLEventListenerAfterVisible) {
+ glWindow.addGLEventListener(demo);
+ glWindow.display();
+ }
+
+ return glWindow;
+ }
+
+ static void destroyWindow(GLWindow glWindow) {
+ if(null!=glWindow) {
+ glWindow.invalidate();
+ Assert.assertEquals(false,glWindow.isNativeValid());
+ Assert.assertEquals(false,glWindow.isValid());
+ }
+ }
+
+ @Test
+ public void testWindowNativeRecreate01aSimple() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ GLWindow window = createWindow(null, caps, width, height,
+ true /* onscreen */, false /* undecorated */,
+ false /*addGLEventListenerAfterVisible*/);
+
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+ window.destroy();
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ window.display();
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ window.setVisible(true);
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+
+ window.setVisible(false);
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ destroyWindow(window);
+ }
+
+ @Test
+ public void testWindowNativeRecreate01bSimple() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ GLWindow window = createWindow(null, caps, width, height,
+ true /* onscreen */, false /* undecorated */,
+ true /*addGLEventListenerAfterVisible*/);
+
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+ window.destroy();
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ window.display();
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ window.setVisible(true);
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+
+ window.setVisible(false);
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ destroyWindow(window);
+ }
+
+ @Test
+ public void testWindowDecor01aSimple() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ GLWindow window = createWindow(null, caps, width, height,
+ true /* onscreen */, false /* undecorated */,
+ false /*addGLEventListenerAfterVisible*/);
+ System.out.println("Created: "+window);
+ int state;
+ for(state=0; state*100<durationPerTest; state++) {
+ Thread.sleep(100);
+ }
+ System.out.println("duration: "+window.getDuration());
+ destroyWindow(window);
+ }
+
+ @Test
+ public void testWindowDecor01bSimple() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ GLWindow window = createWindow(null, caps, width, height,
+ true /* onscreen */, false /* undecorated */,
+ true /*addGLEventListenerAfterVisible*/);
+ System.out.println("Created: "+window);
+ int state;
+ for(state=0; state*100<durationPerTest; state++) {
+ Thread.sleep(100);
+ }
+ System.out.println("duration: "+window.getDuration());
+ destroyWindow(window);
+ }
+
+ @Test
+ public void testWindowDecor02DestroyWinTwiceA() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ GLWindow window = createWindow(null, caps, width, height,
+ true /* onscreen */, false /* undecorated */,
+ false /*addGLEventListenerAfterVisible*/);
+ int state;
+ for(state=0; state*100<durationPerTest; state++) {
+ Thread.sleep(100);
+ }
+ System.out.println("duration: "+window.getDuration());
+ destroyWindow(window);
+ }
+
+ @Test
+ public void testWindowDecor03TwoWinOneDisplay() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+ GLWindow window1 = createWindow(screen, caps, width, height,
+ true /* onscreen */, false /* undecorated */,
+ false /*addGLEventListenerAfterVisible*/);
+ Assert.assertNotNull(window1);
+
+ GLWindow window2 = createWindow(screen, caps, width, height,
+ true /* onscreen */, false /* undecorated */,
+ false /*addGLEventListenerAfterVisible*/);
+ Assert.assertNotNull(window2);
+
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+
+ Assert.assertEquals(2,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+
+ int state;
+ for(state=0; state*100<durationPerTest; state++) {
+ Thread.sleep(100);
+ }
+ System.out.println("duration1: "+window1.getDuration());
+ System.out.println("duration2: "+window2.getDuration());
+
+ destroyWindow(window1);
+ destroyWindow(window2);
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(false,display.getEDTUtil().isRunning());
+
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+ }
+
+ @Test
+ public void testWindowDecor03TwoWinTwoDisplays() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+
+ Display display1 = NewtFactory.createDisplay(null, false); // local display
+ Assert.assertNotNull(display1);
+ Display display2 = NewtFactory.createDisplay(null, false); // local display
+ Assert.assertNotNull(display2);
+ Assert.assertNotSame(display1, display2);
+
+ Screen screen1 = NewtFactory.createScreen(display1, 0); // screen 0
+ Assert.assertNotNull(screen1);
+ GLWindow window1 = createWindow(screen1, caps, width, height,
+ true /* onscreen */, false /* undecorated */,
+ false /*addGLEventListenerAfterVisible*/);
+ Assert.assertNotNull(window1);
+
+ Screen screen2 = NewtFactory.createScreen(display2, 0); // screen 0
+ Assert.assertNotNull(screen2);
+ GLWindow window2 = createWindow(screen2, caps, width, height,
+ true /* onscreen */, false /* undecorated */,
+ false /*addGLEventListenerAfterVisible*/);
+ Assert.assertNotNull(window2);
+
+ Assert.assertEquals(2,Display.getActiveDisplayNumber());
+
+ Assert.assertEquals(1,display1.getReferenceCount());
+ Assert.assertEquals(true,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(1,screen1.getReferenceCount());
+ Assert.assertEquals(true,screen1.isNativeValid());
+
+ Assert.assertEquals(1,display2.getReferenceCount());
+ Assert.assertEquals(true,display2.isNativeValid());
+ Assert.assertNotNull(display2.getEDTUtil());
+ Assert.assertEquals(true,display2.getEDTUtil().isRunning());
+ Assert.assertEquals(1,screen2.getReferenceCount());
+ Assert.assertEquals(true,screen2.isNativeValid());
+
+ int state;
+ for(state=0; state*100<durationPerTest; state++) {
+ Thread.sleep(100);
+ }
+ System.out.println("duration1: "+window1.getDuration());
+ System.out.println("duration2: "+window2.getDuration());
+
+ // It is observed that some X11 drivers, eg ATI, fglrx 8.78.6,
+ // are quite sensitive to multiple Display connections (NEWT Display -> X11 Display).
+ // In such cases, closing displays shall happen in the same order as
+ // opening them, otherwise some driver related bug appears.
+ // You may test this, ie just reverse the destroy order below.
+ // See also native test: jogl/test/native/displayMultiple02.c
+ destroyWindow(window1);
+ destroyWindow(window2);
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ Assert.assertEquals(0,display1.getReferenceCount());
+ Assert.assertEquals(false,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(false,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen1.getReferenceCount());
+ Assert.assertEquals(false,screen1.isNativeValid());
+
+ Assert.assertEquals(0,display2.getReferenceCount());
+ Assert.assertEquals(false,display2.isNativeValid());
+ Assert.assertNotNull(display2.getEDTUtil());
+ Assert.assertEquals(false,display2.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen2.getReferenceCount());
+ Assert.assertEquals(false,screen2.isNativeValid());
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ if(!MiscUtils.setFieldIfExists(demo, "window", glWindow)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ System.out.println("durationPerTest: "+durationPerTest);
+ String tstname = TestGLWindows01NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java
new file mode 100644
index 000000000..6582a96c0
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java
@@ -0,0 +1,303 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt;
+
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.media.opengl.*;
+
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import java.io.IOException;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestGLWindows02NEWTAnimated extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+ static long durationPerTest = 100; // ms
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ glp = GLProfile.getDefault();
+ }
+
+ static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height, boolean onscreen, boolean undecorated) {
+ Assert.assertNotNull(caps);
+ caps.setOnscreen(onscreen);
+ // System.out.println("Requested: "+caps);
+
+ //
+ // Create native windowing resources .. X11/Win/OSX
+ //
+ GLWindow glWindow;
+ if(null!=screen) {
+ Window window = NewtFactory.createWindow(screen, caps);
+ Assert.assertNotNull(window);
+ glWindow = GLWindow.create(window);
+ } else {
+ glWindow = GLWindow.create(caps);
+ }
+ Assert.assertNotNull(glWindow);
+ glWindow.setUndecorated(onscreen && undecorated);
+
+ GLEventListener demo = new Gears();
+ setDemoFields(demo, glWindow);
+ glWindow.addGLEventListener(demo);
+ glWindow.addWindowListener(new TraceWindowAdapter());
+ Assert.assertEquals(false,glWindow.isNativeValid());
+
+ glWindow.setSize(width, height);
+ Assert.assertEquals(false,glWindow.isVisible());
+ glWindow.setVisible(true);
+ Assert.assertEquals(true,glWindow.isVisible());
+ Assert.assertEquals(true,glWindow.isNativeValid());
+ // Assert.assertEquals(width,glWindow.getWidth());
+ // Assert.assertEquals(height,glWindow.getHeight());
+ // System.out.println("Created: "+glWindow);
+
+ //
+ // Create native OpenGL resources .. XGL/WGL/CGL ..
+ // equivalent to GLAutoDrawable methods: setVisible(true)
+ //
+ GLCapabilitiesImmutable caps2 = glWindow.getChosenGLCapabilities();
+ Assert.assertNotNull(caps2);
+ Assert.assertTrue(caps2.getGreenBits()>=5);
+ Assert.assertTrue(caps2.getBlueBits()>=5);
+ Assert.assertTrue(caps2.getRedBits()>=5);
+ Assert.assertEquals(caps2.isOnscreen(),onscreen);
+
+ return glWindow;
+ }
+
+ static void destroyWindow(GLWindow glWindow) {
+ if(null!=glWindow) {
+ glWindow.destroy();
+ }
+ }
+
+ @Test
+ public void testWindowDecor01Simple() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ GLWindow window = createWindow(null, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Animator animator = new Animator(window);
+ Assert.assertTrue(animator.start());
+ while(animator.isAnimating() && animator.getDuration()<durationPerTest) {
+ Thread.sleep(100);
+ }
+ destroyWindow(window);
+ Assert.assertEquals(true, animator.isAnimating());
+ Assert.assertTrue(animator.stop());
+ }
+
+ @Test
+ public void testWindowDecor02DestroyWinTwiceA() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ GLWindow window = createWindow(null, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Animator animator = new Animator(window);
+ Assert.assertTrue(animator.start());
+ while(animator.isAnimating() && animator.getDuration()<durationPerTest) {
+ Thread.sleep(100);
+ }
+ destroyWindow(window);
+ destroyWindow(window);
+ Assert.assertEquals(true, animator.isAnimating());
+ Assert.assertTrue(animator.stop());
+ }
+
+ @Test
+ public void testWindowDecor03TwoWinOneDisplay() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+ GLWindow window1 = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Assert.assertNotNull(window1);
+ window1.setPosition(0, 0);
+
+ GLWindow window2 = createWindow(screen, caps, width-10, height-10, true /* onscreen */, false /* undecorated */);
+ Assert.assertNotNull(window2);
+ window2.setPosition(screen.getWidth()-width, 0);
+
+ Animator animator = new Animator();
+ Assert.assertEquals(false, animator.isStarted());
+ Assert.assertEquals(false, animator.isAnimating());
+ Assert.assertEquals(false, animator.isPaused());
+
+ Assert.assertTrue(animator.start());
+ Assert.assertEquals(true, animator.isStarted());
+ Assert.assertEquals(false, animator.isAnimating());
+ Assert.assertEquals(false, animator.isPaused());
+
+ animator.add(window1);
+ Assert.assertEquals(true, animator.isStarted());
+ Assert.assertEquals(true, animator.isAnimating());
+ Assert.assertEquals(false, animator.isPaused());
+
+ animator.add(window2);
+ Assert.assertEquals(true, animator.isStarted());
+ Assert.assertEquals(true, animator.isAnimating());
+ Assert.assertEquals(false, animator.isPaused());
+
+ while(animator.isAnimating() && animator.getDuration()<durationPerTest) {
+ Thread.sleep(100);
+ }
+ window1.invalidate();
+ Assert.assertEquals(true, animator.isStarted());
+ Assert.assertEquals(true, animator.isAnimating());
+ Assert.assertEquals(false, animator.isPaused());
+
+ while(animator.isAnimating() && animator.getDuration()<2*durationPerTest) {
+ Thread.sleep(100);
+ }
+ window2.invalidate();
+ Assert.assertEquals(true, animator.isStarted());
+ Assert.assertEquals(false, animator.isAnimating());
+ Assert.assertEquals(false, animator.isPaused());
+ Assert.assertTrue(animator.stop());
+ }
+
+ @Test
+ public void testWindowDecor03TwoWinTwoDisplays() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+
+ Display display1 = NewtFactory.createDisplay(null, false); // local display
+ Assert.assertNotNull(display1);
+ Display display2 = NewtFactory.createDisplay(null, false); // local display
+ Assert.assertNotNull(display2);
+ Assert.assertNotSame(display1, display2);
+
+ Screen screen1 = NewtFactory.createScreen(display1, 0); // screen 0
+ Assert.assertNotNull(screen1);
+ GLWindow window1 = createWindow(screen1, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Assert.assertNotNull(window1);
+ window1.setPosition(0, 0);
+
+ Screen screen2 = NewtFactory.createScreen(display2, 0); // screen 0
+ Assert.assertNotNull(screen2);
+ GLWindow window2 = createWindow(screen2, caps, width-10, height-10, true /* onscreen */, false /* undecorated */);
+ Assert.assertNotNull(window2);
+ window2.setPosition(screen2.getWidth()-width, 0);
+
+ Animator animator = new Animator();
+ Assert.assertEquals(false, animator.isStarted());
+ Assert.assertEquals(false, animator.isAnimating());
+ Assert.assertEquals(false, animator.isPaused());
+
+ Assert.assertTrue(animator.start());
+ Assert.assertEquals(true, animator.isStarted());
+ Assert.assertEquals(false, animator.isAnimating());
+ Assert.assertEquals(false, animator.isPaused());
+
+ animator.add(window1);
+ Assert.assertEquals(true, animator.isStarted());
+ Assert.assertEquals(true, animator.isAnimating());
+ Assert.assertEquals(false, animator.isPaused());
+
+ animator.add(window2);
+ Assert.assertEquals(true, animator.isStarted());
+ Assert.assertEquals(true, animator.isAnimating());
+ Assert.assertEquals(false, animator.isPaused());
+
+ while(animator.isAnimating() && animator.getDuration()<durationPerTest) {
+ Thread.sleep(100);
+ }
+ destroyWindow(window1);
+ Assert.assertEquals(true, animator.isStarted());
+ Assert.assertEquals(true, animator.isAnimating());
+ Assert.assertEquals(false, animator.isPaused());
+
+ while(animator.isAnimating() && animator.getDuration()<2*durationPerTest) {
+ Thread.sleep(100);
+ }
+ destroyWindow(window2);
+ Assert.assertEquals(true, animator.isStarted());
+ Assert.assertEquals(true, animator.isAnimating());
+ Assert.assertEquals(false, animator.isPaused());
+
+ Assert.assertEquals(true, animator.pause());
+ Assert.assertEquals(true, animator.isStarted());
+ Assert.assertEquals(false, animator.isAnimating());
+ Assert.assertEquals(true, animator.isPaused());
+
+ Assert.assertEquals(true, animator.resume());
+ Assert.assertEquals(true, animator.isStarted());
+ Assert.assertEquals(true, animator.isAnimating());
+ Assert.assertEquals(false, animator.isPaused());
+
+ Assert.assertTrue(animator.stop());
+ Assert.assertEquals(false, animator.isStarted());
+ Assert.assertEquals(false, animator.isAnimating());
+ Assert.assertEquals(false, animator.isPaused());
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ if(!MiscUtils.setFieldIfExists(demo, "window", glWindow)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ String tstname = TestGLWindows02NEWTAnimated.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestListenerCom01AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestListenerCom01AWT.java
new file mode 100644
index 000000000..b2068d976
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestListenerCom01AWT.java
@@ -0,0 +1,167 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import java.awt.Button;
+import java.awt.BorderLayout;
+import java.awt.Canvas;
+import java.awt.Frame;
+
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import com.jogamp.newt.awt.NewtCanvasAWT;
+
+import java.io.IOException;
+
+import com.jogamp.opengl.test.junit.util.*;
+import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquare;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestListenerCom01AWT extends UITestCase {
+ static int width, height;
+ static long durationPerTest = 500;
+ static boolean verbose = false;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ }
+
+ @Test
+ public void testListenerStringPassingAndOrder() throws InterruptedException {
+ // setup NEWT GLWindow ..
+ GLWindow glWindow = GLWindow.create(new GLCapabilities(null));
+ Assert.assertNotNull(glWindow);
+ glWindow.setTitle("NEWT - CHILD");
+
+ System.out.println("durationPerTest "+durationPerTest);
+
+ GLEventListener demo = new Gears();
+ setDemoFields(demo, glWindow, false);
+ glWindow.addGLEventListener(demo);
+
+ WindowEventCom1 wl1 = new WindowEventCom1();
+ WindowEventCom2 wl2 = new WindowEventCom2();
+ WindowEventCom3 wl3 = new WindowEventCom3();
+
+ // TraceWindowAdapter wlT = new TraceWindowAdapter();
+ // glWindow.addWindowListener(0, wlT);
+ // Assert.assertEquals(wlT, glWindow.getWindowListener(0));
+
+ glWindow.addWindowListener(0, wl3);
+ glWindow.addWindowListener(0, wl2);
+ glWindow.addWindowListener(0, wl1);
+
+ Assert.assertEquals(wl1, glWindow.getWindowListener(0));
+ Assert.assertEquals(wl2, glWindow.getWindowListener(1));
+ Assert.assertEquals(wl3, glWindow.getWindowListener(2));
+
+ // attach NEWT GLWindow to AWT Canvas
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow);
+ Frame frame = new Frame("AWT Parent Frame");
+ frame.add(newtCanvasAWT);
+ frame.setSize(width, height);
+ frame.setVisible(true);
+
+ Animator animator1 = new Animator(glWindow);
+ animator1.start();
+ while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) {
+ Thread.sleep(100);
+ width+=10; height+=10;
+ frame.setSize(width, height);
+ }
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+
+ frame.dispose();
+ glWindow.invalidate();
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ Window window = glWindow.getWindow();
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ verbose = true;
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ String tstname = TestListenerCom01AWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteGLWindows01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteGLWindows01NEWT.java
new file mode 100644
index 000000000..96ea861a7
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteGLWindows01NEWT.java
@@ -0,0 +1,161 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt;
+
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.media.opengl.*;
+import com.jogamp.opengl.util.Animator;
+
+import com.jogamp.newt.*;
+import com.jogamp.newt.opengl.*;
+import java.io.IOException;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+import javax.media.nativewindow.AbstractGraphicsDevice;
+import javax.media.nativewindow.NativeWindowException;
+
+public class TestRemoteGLWindows01NEWT extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+ static long durationPerTest = 100; // ms
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ // GLProfile.initSingleton(false);
+ width = 640;
+ height = 480;
+ glp = GLProfile.getDefault();
+ }
+
+ static GLWindow createWindow(Screen screen, GLCapabilities caps)
+ throws InterruptedException
+ {
+ Assert.assertNotNull(caps);
+ //
+ // Create native windowing resources .. X11/Win/OSX
+ //
+ GLWindow glWindow;
+ if(null!=screen) {
+ glWindow = GLWindow.create(screen, caps);
+ Assert.assertNotNull(glWindow);
+ } else {
+ glWindow = GLWindow.create(caps);
+ Assert.assertNotNull(glWindow);
+ }
+
+ GLEventListener demo = new Gears();
+ glWindow.addGLEventListener(demo);
+
+ glWindow.setSize(512, 512);
+ glWindow.setVisible(true);
+ Assert.assertEquals(true,glWindow.isVisible());
+ Assert.assertEquals(true,glWindow.isNativeValid());
+
+ return glWindow;
+ }
+
+ static void destroyWindow(GLWindow glWindow) {
+ if(null!=glWindow) {
+ glWindow.invalidate();
+ Assert.assertEquals(false,glWindow.isNativeValid());
+ Assert.assertEquals(false,glWindow.isValid());
+ }
+ }
+
+ @Test
+ public void testRemoteWindow01() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ GLWindow window1 = createWindow(null, caps); // local
+ Assert.assertEquals(true,window1.isNativeValid());
+ Assert.assertEquals(true,window1.isVisible());
+ AbstractGraphicsDevice device1 = window1.getScreen().getDisplay().getGraphicsDevice();
+
+ System.err.println("GLProfiles window1: "+device1.getConnection()+": "+GLProfile.glAvailabilityToString(device1));
+
+ Animator animator1 = new Animator(window1);
+ animator1.start();
+
+ // Eager initialization of NEWT Display -> AbstractGraphicsDevice -> GLProfile (device)
+ Display display2 = NewtFactory.createDisplay("charelle:0.0"); // remote display
+ try {
+ display2.createNative();
+ } catch (NativeWindowException nwe) {
+ System.err.println(nwe);
+ Assume.assumeNoException(nwe);
+ destroyWindow(window1);
+ return;
+ }
+ AbstractGraphicsDevice device2 = display2.getGraphicsDevice();
+ GLProfile.initProfiles(device2); // just to make sure
+ System.err.println("");
+ System.err.println("GLProfiles window2: "+device2.getConnection()+": "+GLProfile.glAvailabilityToString(device2));
+
+ Screen screen2 = NewtFactory.createScreen(display2, 0); // screen 0
+ GLWindow window2 = createWindow(screen2, caps); // remote
+ Assert.assertEquals(true,window2.isNativeValid());
+ Assert.assertEquals(true,window2.isVisible());
+
+ Animator animator2 = new Animator(window2);
+ animator2.start();
+
+ for(int state=0; state*100<durationPerTest; state++) {
+ Thread.sleep(100);
+ }
+
+ destroyWindow(window1);
+ destroyWindow(window2);
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ System.out.println("durationPerTest: "+durationPerTest);
+ String tstname = TestRemoteGLWindows01NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteWindow01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteWindow01NEWT.java
new file mode 100644
index 000000000..f0cd3b89f
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteWindow01NEWT.java
@@ -0,0 +1,139 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt;
+
+
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.media.nativewindow.*;
+
+import com.jogamp.newt.*;
+import java.io.IOException;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+public class TestRemoteWindow01NEWT extends UITestCase {
+ static int width, height;
+
+ @BeforeClass
+ public static void initClass() {
+ NativeWindowFactory.initSingleton(true);
+ width = 640;
+ height = 480;
+ }
+
+ static Window createWindow(Screen screen, Capabilities caps, int width, int height, boolean onscreen, boolean undecorated) {
+ Assert.assertNotNull(caps);
+ caps.setOnscreen(onscreen);
+ // System.out.println("Requested: "+caps);
+
+ //
+ // Create native windowing resources .. X11/Win/OSX
+ //
+ Window window = NewtFactory.createWindow(screen, caps);
+ Assert.assertNotNull(window);
+ window.setUndecorated(onscreen && undecorated);
+ window.setSize(width, height);
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+ window.setVisible(true);
+ Assert.assertEquals(true,window.isVisible());
+ Assert.assertEquals(true,window.isNativeValid());
+ // Assert.assertEquals(width,window.getWidth());
+ // Assert.assertEquals(height,window.getHeight());
+ // System.out.println("Created: "+window);
+
+ //
+ // Create native OpenGL resources .. XGL/WGL/CGL ..
+ // equivalent to GLAutoDrawable methods: setVisible(true)
+ //
+ CapabilitiesImmutable chosenCapabilities = window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities();
+ Assert.assertNotNull(chosenCapabilities);
+ Assert.assertTrue(chosenCapabilities.getGreenBits()>5);
+ Assert.assertTrue(chosenCapabilities.getBlueBits()>5);
+ Assert.assertTrue(chosenCapabilities.getRedBits()>5);
+ Assert.assertEquals(chosenCapabilities.isOnscreen(),onscreen);
+
+ return window;
+ }
+
+ static void destroyWindow(Display display, Screen screen, Window window) {
+ if(null!=window) {
+ window.destroy();
+ }
+ if(null!=screen) {
+ screen.destroy();
+ }
+ if(null!=display) {
+ display.destroy();
+ }
+ }
+
+ @Test
+ public void testRemoteWindow01() throws InterruptedException {
+ Capabilities caps = new Capabilities();
+ Display display1 = NewtFactory.createDisplay(null); // local display
+ Screen screen1 = NewtFactory.createScreen(display1, 0); // screen 0
+ Window window1 = createWindow(screen1, caps, width, height, true /* onscreen */, false /* undecorated */);
+ window1.setVisible(true);
+
+ Assert.assertEquals(true,window1.isNativeValid());
+ Assert.assertEquals(true,window1.isVisible());
+
+ Display display2 = NewtFactory.createDisplay("charelle:0.0"); // remote display
+ try {
+ display2.createNative();
+ } catch (NativeWindowException nwe) {
+ System.err.println(nwe);
+ Assume.assumeNoException(nwe);
+ destroyWindow(display1, screen1, window1);
+ return;
+ }
+ Screen screen2 = NewtFactory.createScreen(display2, 0); // screen 0
+ Window window2 = createWindow(screen2, caps, width, height, true /* onscreen */, false /* undecorated */);
+ window2.setVisible(true);
+
+ Assert.assertEquals(true,window2.isNativeValid());
+ Assert.assertEquals(true,window2.isVisible());
+
+ Thread.sleep(500); // 500 ms
+
+ destroyWindow(display1, screen1, window1);
+ destroyWindow(display2, screen2, window2);
+ }
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestRemoteWindow01NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java
new file mode 100644
index 000000000..846013b1d
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java
@@ -0,0 +1,140 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt;
+
+import java.io.IOException;
+import javax.media.nativewindow.NativeWindowFactory;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.jogamp.newt.Display;
+import com.jogamp.newt.NewtFactory;
+import com.jogamp.newt.Screen;
+import com.jogamp.newt.Window;
+import com.jogamp.newt.ScreenMode;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.newt.util.MonitorMode;
+import com.jogamp.newt.util.ScreenModeUtil;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import java.util.Iterator;
+import java.util.List;
+import javax.media.nativewindow.Capabilities;
+import javax.media.nativewindow.util.Dimension;
+import javax.media.nativewindow.util.DimensionReadOnly;
+import javax.media.nativewindow.util.SurfaceSize;
+
+public class TestScreenMode00NEWT extends UITestCase {
+ static int width, height;
+
+ static int waitTimeShort = 4; //1 sec
+ static int waitTimeLong = 6; //6 sec
+
+
+
+ @BeforeClass
+ public static void initClass() {
+ NativeWindowFactory.initSingleton(true);
+ width = 640;
+ height = 480;
+ }
+
+ @Test
+ public void testScreenModeInfo00() throws InterruptedException {
+ DimensionReadOnly res = new Dimension(640, 480);
+ SurfaceSize surfsz = new SurfaceSize(res, 32);
+ DimensionReadOnly mm = new Dimension(500, 400);
+ MonitorMode mon = new MonitorMode(surfsz, mm, 60);
+ ScreenMode sm_out = new ScreenMode(mon, 90);
+ System.err.println("00 out: "+sm_out);
+
+ int[] props = ScreenModeUtil.streamOut(sm_out);
+ ScreenMode sm_in = ScreenModeUtil.streamIn(props, 0);
+ System.err.println("00 in : "+sm_in);
+
+ Assert.assertEquals(sm_in.getMonitorMode().getSurfaceSize().getResolution(),
+ sm_out.getMonitorMode().getSurfaceSize().getResolution());
+
+ Assert.assertEquals(sm_in.getMonitorMode().getSurfaceSize(),
+ sm_out.getMonitorMode().getSurfaceSize());
+
+ Assert.assertEquals(sm_in.getMonitorMode().getScreenSizeMM(),
+ sm_out.getMonitorMode().getScreenSizeMM());
+
+ Assert.assertEquals(sm_in.getMonitorMode(), sm_out.getMonitorMode());
+
+ Assert.assertEquals(sm_in, sm_out);
+
+ Assert.assertEquals(sm_out.hashCode(), sm_in.hashCode());
+ }
+
+ @Test
+ public void testScreenModeInfo01() throws InterruptedException {
+ Capabilities caps = new Capabilities();
+ Window window = NewtFactory.createWindow(caps);
+ window.setSize(width, height);
+ window.setVisible(true);
+
+ Screen screen = window.getScreen();
+
+ List screenModes = screen.getScreenModes();
+ if(null != screenModes) {
+ Assert.assertTrue(screenModes.size()>0);
+ int i=0;
+ for(Iterator iter=screenModes.iterator(); iter.hasNext(); i++) {
+ System.err.println(i+": "+iter.next());
+ }
+ ScreenMode sm_o = screen.getOriginalScreenMode();
+ Assert.assertNotNull(sm_o);
+ ScreenMode sm_c = screen.getOriginalScreenMode();
+ Assert.assertNotNull(sm_c);
+ System.err.println("orig: "+sm_o);
+ System.err.println("curr: "+sm_c);
+ } else {
+ // no support ..
+ System.err.println("Your platform has no ScreenMode change support, sorry");
+ }
+
+ window.invalidate();
+
+ Assert.assertEquals(false,window.isVisible());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(false,screen.getDisplay().isNativeValid());
+ }
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestScreenMode00NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01NEWT.java
new file mode 100644
index 000000000..ffff682dc
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01NEWT.java
@@ -0,0 +1,284 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt;
+
+import java.io.IOException;
+import javax.media.nativewindow.NativeWindowFactory;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+
+import com.jogamp.opengl.util.Animator;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.jogamp.newt.Display;
+import com.jogamp.newt.NewtFactory;
+import com.jogamp.newt.Screen;
+import com.jogamp.newt.Window;
+import com.jogamp.newt.ScreenMode;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.newt.util.ScreenModeUtil;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import java.util.List;
+import javax.media.nativewindow.util.Dimension;
+
+public class TestScreenMode01NEWT extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+
+ static int waitTimeShort = 1000; // 1 sec
+ static int waitTimeLong = 5000; // 5 sec
+
+
+
+ @BeforeClass
+ public static void initClass() {
+ NativeWindowFactory.initSingleton(true);
+ width = 640;
+ height = 480;
+ glp = GLProfile.getDefault();
+ }
+
+ static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height, boolean onscreen, boolean undecorated) {
+ Assert.assertNotNull(caps);
+ caps.setOnscreen(onscreen);
+
+ GLWindow window = GLWindow.create(screen, caps);
+ window.setSize(width, height);
+ window.addGLEventListener(new Gears());
+ Assert.assertNotNull(window);
+ window.setVisible(true);
+ return window;
+ }
+
+ static void destroyWindow(Window window) {
+ if(null!=window) {
+ window.destroy();
+ }
+ }
+
+ @Test
+ public void testFullscreenChange01() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+
+ GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Animator animator = new Animator(window);
+ animator.start();
+
+ window.setFullscreen(true);
+ Assert.assertEquals(true, window.isFullscreen());
+
+ Thread.sleep(waitTimeShort);
+
+ window.setFullscreen(false);
+ Assert.assertEquals(false, window.isFullscreen());
+
+ Thread.sleep(waitTimeShort);
+
+ animator.stop();
+ destroyWindow(window);
+ }
+
+ @Test
+ public void testScreenModeChange01() throws InterruptedException {
+ Thread.sleep(waitTimeShort);
+
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+ GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Assert.assertNotNull(window);
+
+ List screenModes = screen.getScreenModes();
+ if(null==screenModes) {
+ // no support ..
+ System.err.println("Your platform has no ScreenMode change support, sorry");
+ destroyWindow(window);
+ return;
+ }
+ Assert.assertTrue(screenModes.size()>0);
+
+ Animator animator = new Animator(window);
+ animator.start();
+
+ ScreenMode smCurrent = screen.getCurrentScreenMode();
+ Assert.assertNotNull(smCurrent);
+ ScreenMode smOrig = screen.getOriginalScreenMode();
+ Assert.assertNotNull(smOrig);
+ Assert.assertEquals(smCurrent, smOrig);
+ System.err.println("[0] current/orig: "+smCurrent);
+
+ screenModes = ScreenModeUtil.filterByRate(screenModes, smOrig.getMonitorMode().getRefreshRate());
+ Assert.assertNotNull(screenModes);
+ Assert.assertTrue(screenModes.size()>0);
+ screenModes = ScreenModeUtil.filterByRotation(screenModes, 0);
+ Assert.assertNotNull(screenModes);
+ Assert.assertTrue(screenModes.size()>0);
+ screenModes = ScreenModeUtil.filterByResolution(screenModes, new Dimension(801, 601));
+ Assert.assertNotNull(screenModes);
+ Assert.assertTrue(screenModes.size()>0);
+ screenModes = ScreenModeUtil.getHighestAvailableBpp(screenModes);
+ Assert.assertNotNull(screenModes);
+ Assert.assertTrue(screenModes.size()>0);
+
+ ScreenMode sm = (ScreenMode) screenModes.get(0);
+ System.err.println("[0] set current: "+sm);
+ screen.setCurrentScreenMode(sm);
+ Assert.assertEquals(sm, screen.getCurrentScreenMode());
+ Assert.assertNotSame(smOrig, screen.getCurrentScreenMode());
+
+ Thread.sleep(waitTimeLong);
+
+ // check reset ..
+
+ ScreenMode saveOrigMode = (ScreenMode) smOrig.clone();
+
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+
+ animator.stop();
+ destroyWindow(window);
+
+ Assert.assertEquals(false,window.isVisible());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(false,display.isNativeValid());
+
+ screen.createNative(); // trigger native re-creation
+
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,screen.isNativeValid());
+
+ smCurrent = screen.getCurrentScreenMode();
+ System.err.println("[1] current/orig: "+smCurrent);
+
+ Assert.assertNotNull(smCurrent);
+ Assert.assertEquals(saveOrigMode, smOrig);
+
+ screen.destroy();
+
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(false,display.isNativeValid());
+
+ Thread.sleep(waitTimeShort);
+ }
+
+ @Test
+ public void testScreenModeChangeWithFS01Pre() throws InterruptedException {
+ Thread.sleep(waitTimeShort);
+ testScreenModeChangeWithFS01Impl(true) ;
+ Thread.sleep(waitTimeShort);
+ }
+
+ @Test
+ public void testScreenModeChangeWithFS01Post() throws InterruptedException {
+ Thread.sleep(waitTimeShort);
+ testScreenModeChangeWithFS01Impl(false) ;
+ Thread.sleep(waitTimeShort);
+ }
+
+ protected void testScreenModeChangeWithFS01Impl(boolean preFS) throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Animator animator = new Animator(window);
+ animator.start();
+
+ ScreenMode smOrig = screen.getOriginalScreenMode();
+ List screenModes = screen.getScreenModes();
+ if(null==screenModes) {
+ // no support ..
+ destroyWindow(window);
+ return;
+ }
+ Assert.assertTrue(screenModes.size()>0);
+ screenModes = ScreenModeUtil.filterByRate(screenModes, smOrig.getMonitorMode().getRefreshRate());
+ screenModes = ScreenModeUtil.filterByRotation(screenModes, 0);
+ screenModes = ScreenModeUtil.filterByResolution(screenModes, new Dimension(801, 601));
+ screenModes = ScreenModeUtil.getHighestAvailableBpp(screenModes);
+
+ ScreenMode screenMode = (ScreenMode) screenModes.get(0);
+ Assert.assertNotNull(screenMode);
+
+ if(preFS) {
+ System.err.println("[0] set FS pre 0: "+window.isFullscreen());
+ window.setFullscreen(true);
+ Assert.assertEquals(true, window.isFullscreen());
+ System.err.println("[0] set FS pre X: "+window.isFullscreen());
+ }
+
+ System.err.println("[0] set current: "+screenMode);
+ screen.setCurrentScreenMode(screenMode);
+
+ if(!preFS) {
+ System.err.println("[0] set FS post 0: "+window.isFullscreen());
+ window.setFullscreen(true);
+ Assert.assertEquals(true, window.isFullscreen());
+ System.err.println("[0] set FS post X: "+window.isFullscreen());
+ }
+
+ Thread.sleep(waitTimeLong);
+
+ // check reset ..
+
+ ScreenMode saveOrigMode = (ScreenMode) smOrig.clone();
+
+ animator.stop();
+ destroyWindow(window);
+
+ screen.createNative(); // trigger native re-creation
+
+ ScreenMode smCurrent = screen.getCurrentScreenMode();
+ System.err.println("[1] current/orig: "+smCurrent);
+
+ Assert.assertNotNull(smCurrent);
+ Assert.assertEquals(saveOrigMode, smOrig);
+
+ screen.destroy();
+ }
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestScreenMode01NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02NEWT.java
new file mode 100644
index 000000000..2ec0490f0
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02NEWT.java
@@ -0,0 +1,187 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt;
+
+import java.io.IOException;
+import javax.media.nativewindow.NativeWindowFactory;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+
+import com.jogamp.opengl.util.Animator;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.jogamp.newt.Display;
+import com.jogamp.newt.NewtFactory;
+import com.jogamp.newt.Screen;
+import com.jogamp.newt.Window;
+import com.jogamp.newt.ScreenMode;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.newt.util.ScreenModeUtil;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import java.util.List;
+import javax.media.nativewindow.util.Dimension;
+
+public class TestScreenMode02NEWT extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+
+ static int waitTimeShort = 1000; // 1 sec
+ static int waitTimeLong = 5000; // 5 sec
+
+ @BeforeClass
+ public static void initClass() {
+ NativeWindowFactory.initSingleton(true);
+ width = 640;
+ height = 480;
+ glp = GLProfile.getDefault();
+ }
+
+ static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height, boolean onscreen, boolean undecorated) {
+ Assert.assertNotNull(caps);
+ caps.setOnscreen(onscreen);
+
+ GLWindow window = GLWindow.create(screen, caps);
+ window.setSize(width, height);
+ window.addGLEventListener(new Gears());
+ Assert.assertNotNull(window);
+ window.setVisible(true);
+ Assert.assertTrue(window.isVisible());
+ return window;
+ }
+
+ static void destroyWindow(Window window) {
+ if(null!=window) {
+ window.destroy();
+ }
+ }
+
+ @Test
+ public void testScreenRotationChange01() throws InterruptedException {
+ Thread.sleep(waitTimeShort);
+
+ GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+ GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Assert.assertNotNull(window);
+
+ List screenModes = screen.getScreenModes();
+ if(null==screenModes) {
+ // no support ..
+ System.err.println("Your platform has no ScreenMode change support, sorry");
+ destroyWindow(window);
+ return;
+ }
+ Assert.assertTrue(screenModes.size()>0);
+
+ Animator animator = new Animator(window);
+ animator.start();
+
+ ScreenMode smCurrent = screen.getCurrentScreenMode();
+ Assert.assertNotNull(smCurrent);
+ ScreenMode smOrig = screen.getOriginalScreenMode();
+ Assert.assertNotNull(smOrig);
+ Assert.assertEquals(smCurrent, smOrig);
+ System.err.println("[0] current/orig: "+smCurrent);
+
+ screenModes = ScreenModeUtil.filterByRate(screenModes, smOrig.getMonitorMode().getRefreshRate());
+ Assert.assertNotNull(screenModes);
+ Assert.assertTrue(screenModes.size()>0);
+ screenModes = ScreenModeUtil.filterByRotation(screenModes, 90);
+ if(null==screenModes) {
+ // no rotation support ..
+ System.err.println("Your platform has no rotation support, sorry");
+ destroyWindow(window);
+ return;
+ }
+ Assert.assertTrue(screenModes.size()>0);
+ screenModes = ScreenModeUtil.filterByResolution(screenModes, new Dimension(801, 601));
+ Assert.assertNotNull(screenModes);
+ Assert.assertTrue(screenModes.size()>0);
+ screenModes = ScreenModeUtil.getHighestAvailableBpp(screenModes);
+ Assert.assertNotNull(screenModes);
+ Assert.assertTrue(screenModes.size()>0);
+
+ ScreenMode sm = (ScreenMode) screenModes.get(0);
+ System.err.println("[0] set current: "+sm);
+ screen.setCurrentScreenMode(sm);
+ Assert.assertEquals(sm, screen.getCurrentScreenMode());
+ Assert.assertNotSame(smOrig, screen.getCurrentScreenMode());
+
+ Thread.sleep(waitTimeLong);
+
+ // check reset ..
+
+ ScreenMode saveOrigMode = (ScreenMode) smOrig.clone();
+
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+
+ animator.stop();
+ destroyWindow(window);
+
+ Assert.assertEquals(false,window.isVisible());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(false,display.isNativeValid());
+
+ screen.createNative(); // trigger native re-creation
+
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,screen.isNativeValid());
+
+ smCurrent = screen.getCurrentScreenMode();
+ System.err.println("[1] current/orig: "+smCurrent);
+
+ Assert.assertNotNull(smCurrent);
+ Assert.assertEquals(saveOrigMode, smOrig);
+
+ screen.destroy();
+
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(false,display.isNativeValid());
+
+ Thread.sleep(waitTimeShort);
+ }
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestScreenMode02NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestWindows01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestWindows01NEWT.java
new file mode 100644
index 000000000..5ac6041ac
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/TestWindows01NEWT.java
@@ -0,0 +1,179 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import javax.media.nativewindow.*;
+
+import com.jogamp.newt.*;
+import java.io.IOException;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+public class TestWindows01NEWT extends UITestCase {
+ static int width, height;
+
+ @BeforeClass
+ public static void initClass() {
+ NativeWindowFactory.initSingleton(true);
+ width = 640;
+ height = 480;
+ }
+
+ static Window createWindow(Screen screen, Capabilities caps, int width, int height, boolean onscreen, boolean undecorated) {
+ Assert.assertNotNull(caps);
+ caps.setOnscreen(onscreen);
+ // System.out.println("Requested: "+caps);
+
+ //
+ // Create native windowing resources .. X11/Win/OSX
+ //
+ Window window = NewtFactory.createWindow(screen, caps);
+ Assert.assertNotNull(window);
+ window.setUndecorated(onscreen && undecorated);
+ window.setSize(width, height);
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+ window.setVisible(true);
+ Assert.assertEquals(true,window.isVisible());
+ Assert.assertEquals(true,window.isNativeValid());
+ // Assert.assertEquals(width,window.getWidth());
+ // Assert.assertEquals(height,window.getHeight());
+ // System.out.println("Created: "+window);
+
+ //
+ // Create native OpenGL resources .. XGL/WGL/CGL ..
+ // equivalent to GLAutoDrawable methods: setVisible(true)
+ //
+ CapabilitiesImmutable chosenCapabilities = window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities();
+ Assert.assertNotNull(chosenCapabilities);
+ Assert.assertTrue(chosenCapabilities.getGreenBits()>5);
+ Assert.assertTrue(chosenCapabilities.getBlueBits()>5);
+ Assert.assertTrue(chosenCapabilities.getRedBits()>5);
+ Assert.assertEquals(chosenCapabilities.isOnscreen(),onscreen);
+
+ return window;
+ }
+
+ static void destroyWindow(Display display, Screen screen, Window window) {
+ if(null!=window) {
+ window.destroy();
+ }
+ if(null!=screen) {
+ screen.destroy();
+ }
+ if(null!=display) {
+ display.destroy();
+ }
+ }
+
+ @Test
+ public void testWindowNativeRecreate01Simple() throws InterruptedException {
+ Capabilities caps = new Capabilities();
+ Assert.assertNotNull(caps);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+
+ Window window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ window.destroy();
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+
+ window.setVisible(true);
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+
+ Thread.sleep(100); // 100 ms
+ destroyWindow(display, screen, window);
+ }
+
+ @Test
+ public void testWindowDecor01Simple() throws InterruptedException {
+ Capabilities caps = new Capabilities();
+ Assert.assertNotNull(caps);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+
+ Window window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Thread.sleep(100); // 100 ms
+ destroyWindow(display, screen, window);
+ }
+
+ @Test
+ public void testWindowDecor02DestroyWinTwiceA() throws InterruptedException {
+ Capabilities caps = new Capabilities();
+ Assert.assertNotNull(caps);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+
+ Window window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Thread.sleep(100); // 100 ms
+ destroyWindow(null, null, window);
+ destroyWindow(display, screen, window);
+ }
+
+ @Test
+ public void testWindowDecor03TwoWin() throws InterruptedException {
+ Capabilities caps = new Capabilities();
+ Assert.assertNotNull(caps);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+
+ Window window1 = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Window window2 = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Thread.sleep(100); // 100 ms
+ destroyWindow(null, null, window2);
+ destroyWindow(display, screen, window1);
+ }
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestWindows01NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom1.java b/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom1.java
new file mode 100644
index 000000000..609d443aa
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom1.java
@@ -0,0 +1,42 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt;
+
+import com.jogamp.newt.event.*;
+
+class WindowEventCom1 extends WindowAdapter {
+
+ public void windowResized(WindowEvent e) {
+ e.setAttachment(new String("WindowEventCom1.windowResized: "+e));
+ }
+ public void windowMoved(WindowEvent e) {
+ e.setAttachment(new String("WindowEventCom1.windowMoved: "+e));
+ }
+}
+
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom2.java b/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom2.java
new file mode 100644
index 000000000..d15a3ccd8
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom2.java
@@ -0,0 +1,48 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt;
+
+import com.jogamp.newt.event.*;
+
+class WindowEventCom2 extends WindowAdapter {
+
+ public void windowResized(WindowEvent e) {
+ String str = (String) e.getAttachment();
+ if(null==str) {
+ e.setAttachment(new String("WindowEventCom2.windowResized: "+e));
+ }
+ }
+ public void windowMoved(WindowEvent e) {
+ String str = (String) e.getAttachment();
+ if(null==str) {
+ e.setAttachment(new String("WindowEventCom2.windowMoved: "+e));
+ }
+ }
+}
+
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom3.java b/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom3.java
new file mode 100644
index 000000000..87e5eccbb
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/WindowEventCom3.java
@@ -0,0 +1,44 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt;
+
+import com.jogamp.newt.event.*;
+
+class WindowEventCom3 extends WindowAdapter {
+
+ public void windowResized(WindowEvent e) {
+ String str = (String) e.getAttachment();
+ System.out.println("WindowEventCom3.windowResized: "+str);
+ }
+ public void windowMoved(WindowEvent e) {
+ String str = (String) e.getAttachment();
+ System.out.println("WindowEventCom3.windowMoved: "+str);
+ }
+}
+
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/GLRunnableDummy.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/GLRunnableDummy.java
new file mode 100644
index 000000000..d518616b1
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/GLRunnableDummy.java
@@ -0,0 +1,57 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt.parenting;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import javax.media.opengl.*;
+
+public class GLRunnableDummy implements GLRunnable {
+ float r=0.0f;
+ float g=0.0f;
+ float b=0.0f;
+ float d=0.001f;
+
+ public void run(GLAutoDrawable drawable) {
+ GL2ES1 gl = drawable.getGL().getGL2ES1();
+ gl.glClearColor(r, g, b, 1f);
+ r+=d;
+ if(r>1f) {
+ r=1f;
+ d*=-1f;
+ } else if(r<0f) {
+ r=0f;
+ d*=-1f;
+ }
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/KeyAction.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/KeyAction.java
new file mode 100644
index 000000000..3313ec65c
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/KeyAction.java
@@ -0,0 +1,45 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+
+package com.jogamp.opengl.test.junit.newt.parenting;
+
+import com.jogamp.newt.event.*;
+
+class KeyAction extends KeyAdapter {
+ NEWTEventFiFo eventFifo;
+
+ public KeyAction(NEWTEventFiFo eventFifo) {
+ this.eventFifo = eventFifo;
+ }
+
+ public void keyTyped(KeyEvent e) {
+ eventFifo.put(e);
+ }
+}
+
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java
new file mode 100644
index 000000000..5173d0f22
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java
@@ -0,0 +1,716 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt.parenting;
+
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.media.opengl.*;
+
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+
+import java.io.IOException;
+
+import com.jogamp.opengl.test.junit.util.*;
+import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquare;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestParenting01NEWT extends UITestCase {
+ static int width, height;
+ static long durationPerTest = 500;
+ static long waitAbout10FramesAt30fps = 10*34; // 10 frames @ 30fps
+ static GLCapabilities glCaps;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ glCaps = new GLCapabilities(null);
+ }
+
+ @Test
+ public void testWindowParenting01CreateVisibleDestroy() throws InterruptedException {
+ int x = 0;
+ int y = 0;
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ Display display = null;
+ Screen screen = null;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ Assert.assertNotNull(glWindow1);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+ screen = glWindow1.getScreen();
+ display = screen.getDisplay();
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy");
+ glWindow1.setSize(640, 480);
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+
+ GLWindow glWindow2 = GLWindow.create(glWindow1, glCaps);
+ Assert.assertNotNull(glWindow2);
+ Assert.assertEquals(false, glWindow2.isVisible());
+ Assert.assertEquals(false, glWindow2.isNativeValid());
+ Assert.assertSame(glWindow1,glWindow2.getParent());
+ Assert.assertSame(screen,glWindow2.getScreen());
+ Assert.assertSame(display,glWindow2.getScreen().getDisplay());
+ glWindow2.setSize(320, 240);
+ GLEventListener demo2 = new Gears();
+ setDemoFields(demo2, glWindow2, false);
+ glWindow2.addGLEventListener(demo2);
+
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning()); // GLWindow -> invoke ..
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ // visible test
+ Assert.assertEquals(0, glWindow1.getTotalFrames());
+ Assert.assertEquals(0, glWindow2.getTotalFrames());
+ glWindow1.setVisible(true);
+ System.err.println("Frames for setVisible(true): A1: "+glWindow1.getTotalFrames()+", B1: "+glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow1.getTotalFrames());
+ Assert.assertTrue(0 < glWindow2.getTotalFrames());
+
+ Assert.assertEquals(true, glWindow1.isVisible());
+ Assert.assertEquals(true, glWindow1.isNativeValid());
+ Assert.assertEquals(true, glWindow2.isVisible());
+ Assert.assertEquals(true, glWindow2.isNativeValid());
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(2,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+
+ glWindow1.setVisible(false);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(true, glWindow1.isNativeValid());
+ Assert.assertEquals(false, glWindow2.isVisible());
+ Assert.assertEquals(true, glWindow2.isNativeValid());
+
+ glWindow1.resetCounter();
+ glWindow2.resetCounter();
+ Assert.assertEquals(0, glWindow1.getTotalFrames());
+ Assert.assertEquals(0, glWindow2.getTotalFrames());
+ glWindow1.setVisible(true);
+ System.err.println("Frames for setVisible(true): A2: "+glWindow1.getTotalFrames()+", B2: "+glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow1.getTotalFrames());
+ Assert.assertTrue(0 < glWindow2.getTotalFrames());
+
+ Assert.assertEquals(true, glWindow1.isVisible());
+ Assert.assertEquals(true, glWindow1.isNativeValid());
+ Assert.assertEquals(true, glWindow2.isVisible());
+ Assert.assertEquals(true, glWindow2.isNativeValid());
+
+ glWindow1.resetCounter();
+ glWindow2.resetCounter();
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+ Assert.assertEquals(true, animator1.isAnimating());
+ Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertNotNull(animator1.getThread());
+ Animator animator2 = new Animator(glWindow2);
+ animator2.start();
+ Assert.assertEquals(true, animator2.isAnimating());
+ Assert.assertEquals(false, animator2.isPaused());
+ Assert.assertNotNull(animator2.getThread());
+ while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) {
+ Thread.sleep(100);
+ }
+ System.err.println("Frames for setVisible(true): A3: "+glWindow1.getTotalFrames()+", B3: "+glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow1.getTotalFrames());
+ Assert.assertTrue(0 < glWindow2.getTotalFrames());
+
+ Assert.assertEquals(true, animator1.pause());
+ Assert.assertEquals(false, animator1.isAnimating());
+ Assert.assertEquals(true, animator1.isPaused());
+ Assert.assertNotNull(animator1.getThread());
+ Assert.assertEquals(true, animator2.pause());
+ Assert.assertEquals(false, animator2.isAnimating());
+ Assert.assertEquals(true, animator2.isPaused());
+ Assert.assertNotNull(animator2.getThread());
+
+ glWindow1.resetCounter();
+ glWindow2.resetCounter();
+ Assert.assertEquals(true, animator1.resume());
+ Assert.assertEquals(true, animator1.isAnimating());
+ Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertNotNull(animator1.getThread());
+ Assert.assertEquals(true, animator2.resume());
+ Assert.assertEquals(true, animator2.isAnimating());
+ Assert.assertEquals(false, animator2.isPaused());
+ Assert.assertNotNull(animator2.getThread());
+ Thread.sleep(waitAbout10FramesAt30fps);
+ System.err.println("Frames for setVisible(true): A4: "+glWindow1.getTotalFrames()+", B4: "+glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow1.getTotalFrames());
+ Assert.assertTrue(0 < glWindow2.getTotalFrames());
+
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+ Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertEquals(null, animator1.getThread());
+ animator2.stop();
+ Assert.assertEquals(false, animator2.isAnimating());
+ Assert.assertEquals(false, animator2.isPaused());
+ Assert.assertEquals(null, animator2.getThread());
+
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(2,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+
+ glWindow2.destroy(); // can be recreated, refs are hold
+ Assert.assertEquals(true, glWindow1.isVisible());
+ Assert.assertEquals(true, glWindow1.isNativeValid());
+ Assert.assertEquals(true, glWindow1.isValid());
+ Assert.assertEquals(false, glWindow2.isVisible());
+ Assert.assertEquals(false, glWindow2.isNativeValid());
+ Assert.assertEquals(true, glWindow2.isValid());
+
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(1,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+
+ glWindow1.destroy(); // can be recreated, refs are hold
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertEquals(true, glWindow1.isValid());
+ Assert.assertEquals(false, glWindow2.isVisible());
+ Assert.assertEquals(false, glWindow2.isNativeValid());
+ Assert.assertEquals(true, glWindow2.isValid());
+
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(false,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ // recreation ..
+ glWindow1.resetCounter();
+ glWindow2.resetCounter();
+ Assert.assertEquals(0, glWindow1.getTotalFrames());
+ Assert.assertEquals(0, glWindow2.getTotalFrames());
+ glWindow1.setVisible(true);
+ Assert.assertEquals(true, glWindow1.isVisible());
+ Assert.assertEquals(true, glWindow1.isNativeValid());
+ Assert.assertEquals(true, glWindow2.isVisible());
+ Assert.assertEquals(true, glWindow2.isNativeValid());
+
+ System.err.println("Frames for setVisible(true): A3: "+glWindow1.getTotalFrames()+", B3: "+glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow1.getTotalFrames());
+ Assert.assertTrue(0 < glWindow2.getTotalFrames());
+
+ Assert.assertEquals(1,display.getReferenceCount());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(true,display.getEDTUtil().isRunning());
+ Assert.assertEquals(2,screen.getReferenceCount());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+
+ // chain glwindow1 -> glwindow2 ; can be recreated ..
+ glWindow1.destroy();
+ Assert.assertEquals(true, glWindow1.isValid());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertEquals(true, glWindow2.isValid());
+ Assert.assertEquals(false, glWindow2.isNativeValid());
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(false,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ glWindow1.invalidate();
+ Assert.assertEquals(false, glWindow1.isValid());
+ Assert.assertEquals(false, glWindow2.isValid());
+
+ // test double destroy/invalidate ..
+ glWindow2.invalidate();
+ Assert.assertEquals(false, glWindow2.isValid());
+
+ Assert.assertEquals(0,display.getReferenceCount());
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertNotNull(display.getEDTUtil());
+ Assert.assertEquals(false,display.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen.getReferenceCount());
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ }
+
+ @Test
+ public void testWindowParenting02ReparentTop2WinReparentRecreate() throws InterruptedException {
+ testWindowParenting02ReparentTop2WinImpl(true);
+ }
+
+ @Test
+ public void testWindowParenting02ReparentTop2WinReparentNative() throws InterruptedException {
+ testWindowParenting02ReparentTop2WinImpl(false);
+ }
+
+ /**
+ * @param reparentRecreate true, if the followup reparent should utilize destroy/create, instead of native reparenting
+ */
+ protected void testWindowParenting02ReparentTop2WinImpl(boolean reparentRecreate) throws InterruptedException {
+ int x = 0;
+ int y = 0;
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ Display display1 = null;
+ Screen screen1 = null;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ glWindow1.setTitle("testWindowParenting02ReparentTop2Win");
+ glWindow1.setSize(640, 480);
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+ screen1 = glWindow1.getScreen();
+ display1 = screen1.getDisplay();
+
+ Assert.assertEquals(0,display1.getReferenceCount());
+ Assert.assertEquals(false,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen1.getReferenceCount());
+ Assert.assertEquals(false,screen1.isNativeValid());
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ GLWindow glWindow2 = GLWindow.create(glCaps);
+ glWindow2.setSize(320, 240);
+ GLEventListener demo2 = new Gears();
+ setDemoFields(demo2, glWindow2, false);
+ glWindow2.addGLEventListener(demo2);
+ Assert.assertSame(screen1, glWindow2.getScreen());
+ Assert.assertSame(display1, glWindow2.getScreen().getDisplay());
+
+ Assert.assertEquals(0,display1.getReferenceCount());
+ Assert.assertEquals(false,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen1.getReferenceCount());
+ Assert.assertEquals(false,screen1.isNativeValid());
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ Assert.assertEquals(0, glWindow1.getTotalFrames());
+ glWindow1.setVisible(true);
+ Assert.assertEquals(1,display1.getReferenceCount());
+ Assert.assertEquals(true,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(1,screen1.getReferenceCount());
+ Assert.assertEquals(true,screen1.isNativeValid());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ Assert.assertEquals(true, glWindow1.isVisible());
+ System.err.println("Frames for setVisible(true) A1: "+glWindow1.getTotalFrames());
+ Assert.assertTrue(0 < glWindow1.getTotalFrames());
+
+ Assert.assertEquals(0, glWindow2.getTotalFrames());
+ glWindow2.setVisible(true);
+
+ Assert.assertEquals(1,display1.getReferenceCount());
+ Assert.assertEquals(true,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(2,screen1.getReferenceCount());
+ Assert.assertEquals(true,screen1.isNativeValid());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ Assert.assertEquals(true, glWindow2.isVisible());
+ System.err.println("Frames for setVisible(true) B1: "+glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow1.getTotalFrames());
+
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+ Animator animator2 = new Animator(glWindow2);
+ animator2.start();
+
+ int state = 0;
+ int reparentAction;
+ while(animator1.isAnimating() && animator1.getDuration()<3*durationPerTest) {
+ Thread.sleep(durationPerTest);
+ switch(state) {
+ case 0:
+ // glWindow2 -- child --> glWindow1: compatible
+ Assert.assertEquals(true, glWindow2.isVisible());
+ System.err.println("Frames(1) "+glWindow2.getTotalFrames());
+ reparentAction = glWindow2.reparentWindow(glWindow1, reparentRecreate);
+ System.err.println("Frames(2) "+glWindow2.getTotalFrames());
+ Assert.assertTrue(Window.ReparentAction.ACTION_INVALID < reparentAction);
+ Assert.assertEquals(true, glWindow2.isVisible());
+ Assert.assertEquals(true, glWindow2.isNativeValid());
+ Assert.assertSame(glWindow1,glWindow2.getParent());
+ System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B2: "+glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow2.getTotalFrames());
+
+ Assert.assertEquals(1,display1.getReferenceCount());
+ Assert.assertEquals(true,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(true,screen1.isNativeValid());
+ Assert.assertSame(screen1,glWindow2.getScreen());
+ Assert.assertSame(display1,glWindow2.getScreen().getDisplay());
+ Assert.assertEquals(2,screen1.getReferenceCount());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+
+ break;
+
+ case 1:
+ // glWindow2 --> top
+ Assert.assertEquals(true, glWindow2.isVisible());
+
+ reparentAction = glWindow2.reparentWindow(null, reparentRecreate);
+ Assert.assertTrue(Window.ReparentAction.ACTION_INVALID < reparentAction);
+ Assert.assertEquals(true, glWindow2.isVisible());
+ Assert.assertEquals(true, glWindow2.isNativeValid());
+ Assert.assertNull(glWindow2.getParent());
+ System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B3: "+glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow2.getTotalFrames());
+
+ Assert.assertEquals(1,display1.getReferenceCount());
+ Assert.assertEquals(true,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(true,screen1.isNativeValid());
+ Assert.assertSame(screen1,glWindow2.getScreen());
+ Assert.assertSame(display1,glWindow2.getScreen().getDisplay());
+ Assert.assertEquals(2,screen1.getReferenceCount());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+
+ break;
+ }
+ state++;
+ }
+ //
+ // both windows are now top level
+ //
+
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+ Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertEquals(null, animator1.getThread());
+ animator2.stop();
+ Assert.assertEquals(false, animator2.isAnimating());
+ Assert.assertEquals(false, animator2.isPaused());
+ Assert.assertEquals(null, animator2.getThread());
+
+ // pre-destroy check (both valid and running)
+ Assert.assertEquals(1,display1.getReferenceCount());
+ Assert.assertEquals(true,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(2,screen1.getReferenceCount());
+ Assert.assertEquals(true,screen1.isNativeValid());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+
+ // destroy glWindow2
+ glWindow2.destroy();
+ Assert.assertEquals(true, glWindow1.isValid());
+ Assert.assertEquals(true, glWindow1.isNativeValid());
+ Assert.assertEquals(true, glWindow1.isVisible());
+ Assert.assertEquals(true, glWindow2.isValid());
+ Assert.assertEquals(false, glWindow2.isNativeValid());
+ Assert.assertEquals(false, glWindow2.isVisible());
+
+ Assert.assertEquals(1,display1.getReferenceCount());
+ Assert.assertEquals(true,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(1,screen1.getReferenceCount());
+ Assert.assertEquals(true,screen1.isNativeValid());
+
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+
+ // destroy glWindow1
+ glWindow1.destroy();
+ Assert.assertEquals(true, glWindow1.isValid());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(true, glWindow2.isValid());
+ Assert.assertEquals(false, glWindow2.isNativeValid());
+ Assert.assertEquals(false, glWindow2.isVisible());
+
+ Assert.assertEquals(0,display1.getReferenceCount());
+ Assert.assertEquals(false,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(false,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen1.getReferenceCount());
+ Assert.assertEquals(false,screen1.isNativeValid());
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ glWindow1.invalidate();
+ Assert.assertEquals(false, glWindow1.isValid());
+ Assert.assertEquals(true, glWindow2.isValid());
+
+ glWindow2.invalidate();
+ Assert.assertEquals(false, glWindow2.isValid());
+ }
+
+ @Test
+ public void testWindowParenting03ReparentWin2TopReparentRecreate() throws InterruptedException {
+ testWindowParenting03ReparentWin2TopImpl(true);
+ }
+
+ @Test
+ public void testWindowParenting03ReparentWin2TopReparentNative() throws InterruptedException {
+ testWindowParenting03ReparentWin2TopImpl(false);
+ }
+
+ protected void testWindowParenting03ReparentWin2TopImpl(boolean reparentRecreate) throws InterruptedException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ Display display1 = null;
+ Screen screen1 = null;
+ Display display2 = null;
+ Screen screen2 = null;
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ screen1 = glWindow1.getScreen();
+ display1 = screen1.getDisplay();
+ glWindow1.setTitle("testWindowParenting03ReparentWin2Top");
+ glWindow1.setSize(640, 480);
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+
+ Assert.assertEquals(0,display1.getReferenceCount());
+ Assert.assertEquals(false,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen1.getReferenceCount());
+ Assert.assertEquals(false,screen1.isNativeValid());
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ GLWindow glWindow2 = GLWindow.create(glWindow1, glCaps);
+ screen2 = glWindow2.getScreen();
+ display2 = screen2.getDisplay();
+ glWindow2.setSize(320, 240);
+ GLEventListener demo2 = new Gears();
+ setDemoFields(demo2, glWindow2, false);
+ glWindow2.addGLEventListener(demo2);
+
+ Assert.assertEquals(0,display2.getReferenceCount());
+ Assert.assertEquals(false,display2.isNativeValid());
+ Assert.assertNotNull(display2.getEDTUtil());
+ Assert.assertEquals(true,display2.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen2.getReferenceCount());
+ Assert.assertEquals(false,screen2.isNativeValid());
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ Assert.assertSame(screen1,glWindow2.getScreen());
+ Assert.assertSame(display1,glWindow2.getScreen().getDisplay());
+
+ Assert.assertEquals(0, glWindow1.getTotalFrames());
+ Assert.assertEquals(0, glWindow2.getTotalFrames());
+ glWindow1.setVisible(true);
+ System.err.println("Frames for setVisible(): A1: "+glWindow1.getTotalFrames()+", B1: "+glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow1.getTotalFrames());
+
+ Assert.assertEquals(1,display1.getReferenceCount());
+ Assert.assertEquals(true,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(2,screen1.getReferenceCount());
+ Assert.assertEquals(true,screen1.isNativeValid());
+ Assert.assertSame(glWindow1,glWindow2.getParent());
+ Assert.assertSame(screen1,glWindow2.getScreen());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+ Animator animator2 = new Animator(glWindow2);
+ animator2.start();
+
+ int state = 0;
+ int reparentAction;
+ while(animator1.isAnimating() && animator1.getDuration()<3*durationPerTest) {
+ Thread.sleep(durationPerTest);
+ switch(state) {
+ case 0:
+ Assert.assertEquals(true, glWindow2.isVisible());
+ reparentAction = glWindow2.reparentWindow(null, reparentRecreate);
+ Assert.assertTrue(Window.ReparentAction.ACTION_INVALID < reparentAction);
+ Assert.assertEquals(true, glWindow2.isVisible());
+ Assert.assertEquals(true, glWindow2.isNativeValid());
+ System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B2: "+glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow2.getTotalFrames());
+ Assert.assertNull(glWindow2.getParent());
+ Assert.assertSame(screen1,glWindow2.getScreen());
+ Assert.assertSame(display1,glWindow2.getScreen().getDisplay());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ break;
+ case 1:
+ Assert.assertEquals(true, glWindow2.isVisible());
+ reparentAction = glWindow2.reparentWindow(glWindow1, reparentRecreate);
+ Assert.assertTrue(Window.ReparentAction.ACTION_INVALID < reparentAction);
+ Assert.assertEquals(true, glWindow2.isVisible());
+ Assert.assertEquals(true, glWindow2.isNativeValid());
+ System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B3 "+glWindow2.getTotalFrames());
+ Assert.assertTrue(0 < glWindow2.getTotalFrames());
+ Assert.assertSame(glWindow1,glWindow2.getParent());
+ Assert.assertSame(screen1,glWindow2.getScreen());
+ Assert.assertSame(display1,glWindow2.getScreen().getDisplay());
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+ break;
+ }
+ state++;
+ }
+ //
+ // glwindow2 is child of glwindow1
+ //
+
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+ Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertEquals(null, animator1.getThread());
+ animator2.stop();
+ Assert.assertEquals(false, animator2.isAnimating());
+ Assert.assertEquals(false, animator2.isPaused());
+ Assert.assertEquals(null, animator2.getThread());
+
+ Assert.assertEquals(1,display1.getReferenceCount());
+ Assert.assertEquals(true,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(true,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(2,screen1.getReferenceCount());
+ Assert.assertEquals(true,screen1.isNativeValid());
+ Assert.assertSame(glWindow1,glWindow2.getParent());
+ Assert.assertSame(screen1,glWindow2.getScreen());
+
+ Assert.assertEquals(1,Display.getActiveDisplayNumber());
+
+ glWindow1.destroy(); // should destroy both windows, actually, since glWindow2 is a child
+ Assert.assertEquals(true, glWindow1.isValid());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(true, glWindow2.isValid());
+ Assert.assertEquals(false, glWindow2.isNativeValid());
+ Assert.assertEquals(false, glWindow2.isVisible());
+
+ Assert.assertEquals(0,display1.getReferenceCount());
+ Assert.assertEquals(false,display1.isNativeValid());
+ Assert.assertNotNull(display1.getEDTUtil());
+ Assert.assertEquals(false,display1.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen1.getReferenceCount());
+ Assert.assertEquals(false,screen1.isNativeValid());
+
+ Assert.assertEquals(0,display2.getReferenceCount());
+ Assert.assertEquals(false,display2.isNativeValid());
+ Assert.assertNotNull(display2.getEDTUtil());
+ Assert.assertEquals(false,display2.getEDTUtil().isRunning());
+ Assert.assertEquals(0,screen2.getReferenceCount());
+ Assert.assertEquals(false,screen2.isNativeValid());
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+
+ glWindow2.destroy(); // dbl destroy check ..
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertEquals(false, glWindow2.isNativeValid());
+
+ glWindow1.invalidate(); // parent -> child
+ Assert.assertEquals(false, glWindow1.isValid());
+ Assert.assertEquals(false, glWindow2.isValid());
+
+ Assert.assertEquals(0,Display.getActiveDisplayNumber());
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", glWindow.getWindow())) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ System.err.println("durationPerTest: "+durationPerTest);
+ String tstname = TestParenting01NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
+
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aAWT.java
new file mode 100644
index 000000000..424fff0e2
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aAWT.java
@@ -0,0 +1,443 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt.parenting;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import java.awt.Button;
+import java.awt.BorderLayout;
+import java.awt.Canvas;
+import java.awt.Container;
+import java.awt.Frame;
+import java.awt.Dimension;
+
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import com.jogamp.newt.awt.NewtCanvasAWT;
+
+import java.io.IOException;
+
+import com.jogamp.opengl.test.junit.util.*;
+import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquare;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestParenting01aAWT extends UITestCase {
+ static int width, height;
+ static long durationPerTest = 800;
+ static long waitReparent = 0;
+ static GLCapabilities glCaps;
+
+ @BeforeClass
+ public static void initClass() throws InterruptedException {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ glCaps = new GLCapabilities(null);
+ // Thread.sleep(10000);
+ }
+
+ @Test
+ public void testWindowParenting01CreateVisibleDestroy1() throws InterruptedException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ Assert.assertNotNull(glWindow1);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+ glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy");
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+ Assert.assertNotNull(newtCanvasAWT);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+
+ Frame frame1 = new Frame("AWT Parent Frame");
+ frame1.setLayout(new BorderLayout());
+ frame1.add(new Button("North"), BorderLayout.NORTH);
+ frame1.add(new Button("South"), BorderLayout.SOUTH);
+ frame1.add(new Button("East"), BorderLayout.EAST);
+ frame1.add(new Button("West"), BorderLayout.WEST);
+
+ Container container1 = new Container();
+ container1.setLayout(new BorderLayout());
+ container1.add(new Button("north"), BorderLayout.NORTH);
+ container1.add(new Button("south"), BorderLayout.SOUTH);
+ container1.add(new Button("east"), BorderLayout.EAST);
+ container1.add(new Button("west"), BorderLayout.WEST);
+ container1.add(newtCanvasAWT, BorderLayout.CENTER);
+
+ frame1.add(container1, BorderLayout.CENTER);
+ frame1.setSize(width, height);
+
+ // visible test
+ frame1.setVisible(true);
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+ while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) {
+ Thread.sleep(100);
+ }
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+
+ frame1.setVisible(false);
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ frame1.setVisible(true);
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ frame1.remove(newtCanvasAWT);
+ // Assert.assertNull(glWindow1.getParent());
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ frame1.dispose();
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ glWindow1.invalidate();
+ //Assert.assertEquals(false, glWindow1.isValid());
+ }
+
+ @Test
+ public void testWindowParenting02CreateVisibleDestroy2Defered() throws InterruptedException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ Assert.assertNotNull(glWindow1);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+ Assert.assertNotNull(newtCanvasAWT);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+
+ Frame frame = new Frame("AWT Parent Frame");
+ Assert.assertNotNull(frame);
+ frame.setSize(width, height);
+
+ // visible test
+ frame.setVisible(true);
+
+ frame.add(newtCanvasAWT);
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+ while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) {
+ Thread.sleep(100);
+ }
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+
+ frame.dispose();
+ glWindow1.invalidate();
+ }
+
+ @Test
+ public void testWindowParenting02CreateVisibleDestroy3Odd() throws InterruptedException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+
+ Frame frame = new Frame("AWT Parent Frame");
+ Assert.assertNotNull(frame);
+ frame.setSize(width, height);
+
+ // visible test
+ frame.setVisible(true);
+
+ frame.add(newtCanvasAWT);
+
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+ Assert.assertEquals(true, animator1.isStarted());
+ Assert.assertEquals(true, animator1.isAnimating());
+ while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) {
+ Thread.sleep(100);
+ }
+
+ Assert.assertEquals(true, animator1.isAnimating()); // !!!
+
+ frame.dispose();
+ glWindow1.invalidate();
+ }
+
+ @Test
+ public void testWindowParenting03ReparentNewtWin2Top() throws InterruptedException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+
+ Frame frame = new Frame("AWT Parent Frame");
+ frame.setSize(width, height);
+ frame.setLocation(640, 480);
+ frame.setVisible(true);
+
+ frame.add(newtCanvasAWT);
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+
+ int state = 0;
+ while(animator1.isAnimating() && animator1.getDuration()<3*durationPerTest) {
+ Thread.sleep(durationPerTest);
+ switch(state) {
+ case 0:
+ glWindow1.reparentWindow(null);
+ Assert.assertEquals(true, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+ break;
+ case 1:
+ glWindow1.reparentWindow(newtCanvasAWT.getNativeWindow());
+ Assert.assertEquals(true, glWindow1.isNativeValid());
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+ break;
+ }
+ state++;
+ }
+
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+
+ frame.dispose();
+ glWindow1.invalidate();
+ }
+
+ @Test
+ public void testWindowParenting04ReparentNewtWin2TopLayouted() throws InterruptedException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+
+ Frame frame = new Frame("AWT Parent Frame");
+ frame.setLayout(new BorderLayout());
+ frame.add(new Button("North"), BorderLayout.NORTH);
+ frame.add(new Button("South"), BorderLayout.SOUTH);
+ frame.add(new Button("East"), BorderLayout.EAST);
+ frame.add(new Button("West"), BorderLayout.WEST);
+ frame.setSize(width, height);
+ frame.setLocation(640, 480);
+ frame.setVisible(true);
+
+ frame.add(newtCanvasAWT, BorderLayout.CENTER);
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+
+ int state = 0;
+ while(animator1.isAnimating() && animator1.getDuration()<3*durationPerTest) {
+ Thread.sleep(durationPerTest);
+ switch(state) {
+ case 0:
+ glWindow1.reparentWindow(null);
+ Assert.assertEquals(true, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+ break;
+ case 1:
+ glWindow1.reparentWindow(newtCanvasAWT.getNativeWindow());
+ Assert.assertEquals(true, glWindow1.isNativeValid());
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+ break;
+ }
+ state++;
+ }
+
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+
+ frame.dispose();
+ glWindow1.invalidate();
+ }
+
+ @Test
+ public void testWindowParenting05ReparentAWTWinHopFrame2Frame() throws InterruptedException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ glWindow1.setUndecorated(true);
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+
+ Frame frame1 = new Frame("AWT Parent Frame");
+ frame1.setLayout(new BorderLayout());
+ frame1.add(new Button("North"), BorderLayout.NORTH);
+ frame1.add(new Button("South"), BorderLayout.SOUTH);
+ frame1.add(new Button("East"), BorderLayout.EAST);
+ frame1.add(new Button("West"), BorderLayout.WEST);
+ frame1.setSize(width, height);
+ frame1.setLocation(0, 0);
+ frame1.setVisible(true);
+
+ Frame frame2 = new Frame("AWT Parent Frame");
+ frame2.setLayout(new BorderLayout());
+ frame2.add(new Button("North"), BorderLayout.NORTH);
+ frame2.add(new Button("South"), BorderLayout.SOUTH);
+ frame2.add(new Button("East"), BorderLayout.EAST);
+ frame2.add(new Button("West"), BorderLayout.WEST);
+ frame2.setSize(width, height);
+ frame2.setLocation(640, 480);
+ frame2.setVisible(true);
+
+ frame1.add(newtCanvasAWT, BorderLayout.CENTER);
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+
+ int state = 0;
+ while(animator1.isAnimating() && animator1.getDuration()<3*durationPerTest) {
+ Thread.sleep(durationPerTest);
+ switch(state) {
+ case 0:
+ frame1.remove(newtCanvasAWT);
+ frame2.add(newtCanvasAWT, BorderLayout.CENTER);
+ break;
+ case 1:
+ frame2.remove(newtCanvasAWT);
+ frame1.add(newtCanvasAWT, BorderLayout.CENTER);
+ break;
+ }
+ state++;
+ }
+
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+
+ frame1.dispose();
+ frame2.dispose();
+ glWindow1.invalidate();
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", glWindow.getWindow())) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ } else if(args[i].equals("-wait")) {
+ waitReparent = atoi(args[++i]);
+ }
+ }
+ String tstname = TestParenting01aAWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01bAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01bAWT.java
new file mode 100644
index 000000000..2b8d34423
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01bAWT.java
@@ -0,0 +1,205 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt.parenting;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import java.awt.Button;
+import java.awt.BorderLayout;
+import java.awt.Canvas;
+import java.awt.Frame;
+import java.awt.Dimension;
+
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.FPSAnimator;
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import com.jogamp.newt.awt.NewtCanvasAWT;
+
+import java.io.IOException;
+
+import com.jogamp.opengl.test.junit.util.*;
+import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquare;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestParenting01bAWT extends UITestCase {
+ static int width, height;
+ static long durationPerTest = 800;
+ static long waitReparent = 0;
+ static GLCapabilities glCaps;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ glCaps = new GLCapabilities(null);
+ }
+
+ @Test
+ public void testWindowParenting05ReparentAWTWinHopFrame2FrameFPS25Animator() throws InterruptedException {
+ testWindowParenting05ReparentAWTWinHopFrame2FrameImpl(25);
+ }
+
+ @Test
+ public void testWindowParenting05ReparentAWTWinHopFrame2FrameStdAnimator() throws InterruptedException {
+ testWindowParenting05ReparentAWTWinHopFrame2FrameImpl(0);
+ }
+
+ public void testWindowParenting05ReparentAWTWinHopFrame2FrameImpl(int fps) throws InterruptedException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ glWindow1.setUndecorated(true);
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+
+ Frame frame1 = new Frame("AWT Parent Frame");
+ frame1.setLayout(new BorderLayout());
+ frame1.add(new Button("North"), BorderLayout.NORTH);
+ frame1.add(new Button("South"), BorderLayout.SOUTH);
+ frame1.add(new Button("East"), BorderLayout.EAST);
+ frame1.add(new Button("West"), BorderLayout.WEST);
+ frame1.setSize(width, height);
+ frame1.setLocation(0, 0);
+ frame1.setVisible(true);
+
+ Frame frame2 = new Frame("AWT Parent Frame");
+ frame2.setLayout(new BorderLayout());
+ frame2.add(new Button("North"), BorderLayout.NORTH);
+ frame2.add(new Button("South"), BorderLayout.SOUTH);
+ frame2.add(new Button("East"), BorderLayout.EAST);
+ frame2.add(new Button("West"), BorderLayout.WEST);
+ frame2.setSize(width, height);
+ frame2.setLocation(640, 480);
+ frame2.setVisible(true);
+
+ frame1.add(newtCanvasAWT, BorderLayout.CENTER);
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+
+ GLAnimatorControl animator1;
+ if(fps>0) {
+ animator1 = new FPSAnimator(glWindow1, fps);
+ } else {
+ animator1 = new Animator(glWindow1);
+ }
+ animator1.start();
+
+ int state;
+ for(state=0; state<3; state++) {
+ Thread.sleep(durationPerTest);
+ switch(state) {
+ case 0:
+ frame1.remove(newtCanvasAWT);
+ frame2.add(newtCanvasAWT, BorderLayout.CENTER);
+ break;
+ case 1:
+ frame2.remove(newtCanvasAWT);
+ frame1.add(newtCanvasAWT, BorderLayout.CENTER);
+ break;
+ }
+ }
+
+ Assert.assertEquals(true, animator1.isAnimating());
+ Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertNotNull(animator1.getThread());
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+ Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertEquals(null, animator1.getThread());
+
+ frame1.dispose();
+ frame2.dispose();
+ glWindow1.invalidate();
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ Window window = glWindow.getWindow();
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ } else if(args[i].equals("-wait")) {
+ waitReparent = atoi(args[++i]);
+ }
+ }
+ String tstname = TestParenting01bAWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cAWT.java
new file mode 100644
index 000000000..7321c6ba2
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cAWT.java
@@ -0,0 +1,243 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt.parenting;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import java.awt.Button;
+import java.awt.BorderLayout;
+import java.awt.Canvas;
+import java.awt.Container;
+import java.awt.Frame;
+import java.awt.Dimension;
+
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import com.jogamp.newt.awt.NewtCanvasAWT;
+
+import java.io.IOException;
+
+import com.jogamp.opengl.test.junit.util.*;
+import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquare;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestParenting01cAWT extends UITestCase {
+ static int width, height;
+ static long durationPerTest = 800;
+ static GLCapabilities glCaps;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ glCaps = new GLCapabilities(null);
+ }
+
+ @Test
+ public void testWindowParenting01CreateVisibleDestroy1() throws InterruptedException {
+ int x = 0;
+ int y = 0;
+ int i;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ Assert.assertNotNull(glWindow1);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+ glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy");
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+ Assert.assertNotNull(newtCanvasAWT);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+
+ Frame frame1 = new Frame("AWT Parent Frame");
+ frame1.setLayout(new BorderLayout());
+ frame1.add(new Button("North"), BorderLayout.NORTH);
+ frame1.add(new Button("South"), BorderLayout.SOUTH);
+ frame1.add(new Button("East"), BorderLayout.EAST);
+ frame1.add(new Button("West"), BorderLayout.WEST);
+
+ Container container1 = new Container();
+ container1.setLayout(new BorderLayout());
+ container1.add(new Button("north"), BorderLayout.NORTH);
+ container1.add(new Button("south"), BorderLayout.SOUTH);
+ container1.add(new Button("east"), BorderLayout.EAST);
+ container1.add(new Button("west"), BorderLayout.WEST);
+ container1.add(newtCanvasAWT, BorderLayout.CENTER);
+
+ frame1.add(container1, BorderLayout.CENTER);
+ frame1.setSize(width, height);
+
+ // visible test
+ frame1.setVisible(true);
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+
+ for(i=0; i*100<durationPerTest; i++) {
+ Thread.sleep(100);
+ }
+
+ frame1.setVisible(false);
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ frame1.setVisible(true);
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ frame1.remove(newtCanvasAWT);
+ // Assert.assertNull(glWindow1.getParent());
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ frame1.dispose();
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ glWindow1.invalidate();
+ //Assert.assertEquals(false, glWindow1.isValid());
+ }
+
+ @Test
+ public void testWindowParenting05ReparentAWTWinHopFrame2Frame() throws InterruptedException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ glWindow1.setUndecorated(true);
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+
+ Frame frame1 = new Frame("AWT Parent Frame");
+ frame1.setLayout(new BorderLayout());
+ frame1.add(new Button("North"), BorderLayout.NORTH);
+ frame1.add(new Button("South"), BorderLayout.SOUTH);
+ frame1.add(new Button("East"), BorderLayout.EAST);
+ frame1.add(new Button("West"), BorderLayout.WEST);
+ frame1.setSize(width, height);
+ frame1.setLocation(0, 0);
+ frame1.setVisible(true);
+
+ Frame frame2 = new Frame("AWT Parent Frame");
+ frame2.setLayout(new BorderLayout());
+ frame2.add(new Button("North"), BorderLayout.NORTH);
+ frame2.add(new Button("South"), BorderLayout.SOUTH);
+ frame2.add(new Button("East"), BorderLayout.EAST);
+ frame2.add(new Button("West"), BorderLayout.WEST);
+ frame2.setSize(width, height);
+ frame2.setLocation(640, 480);
+ frame2.setVisible(true);
+
+ frame1.add(newtCanvasAWT, BorderLayout.CENTER);
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+
+ int state;
+ for(state=0; state<3; state++) {
+ Thread.sleep(durationPerTest);
+ switch(state) {
+ case 0:
+ frame1.remove(newtCanvasAWT);
+ frame2.add(newtCanvasAWT, BorderLayout.CENTER);
+ break;
+ case 1:
+ frame2.remove(newtCanvasAWT);
+ frame1.add(newtCanvasAWT, BorderLayout.CENTER);
+ break;
+ }
+ }
+
+ frame1.dispose();
+ frame2.dispose();
+ glWindow1.invalidate();
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ Window window = glWindow.getWindow();
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ String tstname = TestParenting01cAWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java
new file mode 100644
index 000000000..1c155f75a
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java
@@ -0,0 +1,365 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt.parenting;
+
+import java.lang.reflect.*;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.awt.Button;
+import java.awt.BorderLayout;
+import java.awt.Container;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
+
+import javax.media.opengl.*;
+
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import com.jogamp.newt.awt.NewtCanvasAWT;
+
+import java.io.IOException;
+
+import com.jogamp.opengl.test.junit.util.*;
+import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquare;
+
+public class TestParenting01cSwingAWT extends UITestCase {
+ static int width, height;
+ static long durationPerTest = 800;
+ static long waitReparent = 0;
+ static GLCapabilities glCaps;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ glCaps = new GLCapabilities(null);
+ }
+
+ @Test
+ public void testWindowParenting01CreateVisibleDestroy1() throws InterruptedException, InvocationTargetException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ /**
+ * JFrame . JPanel . Container . NewtCanvasAWT . GLWindow
+ */
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ Assert.assertNotNull(glWindow1);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+ glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy");
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+ final GLWindow _glWindow1 = glWindow1;
+ final GLRunnable _glRunnable = new GLRunnableDummy();
+ Thread disturbanceThread = new Thread(new Runnable() {
+ public void run() {
+ System.out.println("$");
+ while(true)
+ {
+ try {
+ _glWindow1.invoke(true, _glRunnable);
+ Thread.yield();
+ } catch (Throwable t) {}
+ }
+ }
+ });
+ disturbanceThread.start();
+
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+ Assert.assertNotNull(newtCanvasAWT);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+
+ Container container1 = new Container();
+ container1.setLayout(new BorderLayout());
+ container1.add(new Button("north"), BorderLayout.NORTH);
+ container1.add(new Button("south"), BorderLayout.SOUTH);
+ container1.add(new Button("east"), BorderLayout.EAST);
+ container1.add(new Button("west"), BorderLayout.WEST);
+ container1.add(newtCanvasAWT, BorderLayout.CENTER);
+
+ JPanel jPanel1 = new JPanel();
+ jPanel1.setLayout(new BorderLayout());
+ jPanel1.add(new Button("north"), BorderLayout.NORTH);
+ jPanel1.add(new Button("south"), BorderLayout.SOUTH);
+ jPanel1.add(new Button("east"), BorderLayout.EAST);
+ jPanel1.add(new Button("west"), BorderLayout.WEST);
+ jPanel1.add(container1, BorderLayout.CENTER);
+
+ JFrame jFrame1 = new JFrame("Swing Parent JFrame");
+ // jFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ jFrame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event!
+ jFrame1.setContentPane(jPanel1);
+ jFrame1.setSize(width, height);
+ System.out.println("Demos: 1 - Visible");
+ jFrame1.setVisible(true); // from here on, we need to run modifications on EDT
+
+ final JFrame _jFrame1 = jFrame1;
+ final JPanel _jPanel1 = jPanel1;
+ final Container _container1 = container1;
+
+ // visible test
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+
+ while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) {
+ Thread.sleep(100);
+ }
+ System.out.println("Demos: 2 - StopAnimator");
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ System.out.println("Demos: 3 - !Visible");
+ _jFrame1.setVisible(false);
+ } });
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ System.out.println("Demos: 4 - Visible");
+ _jFrame1.setVisible(true);
+ } });
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ System.out.println("Demos: 5 - X Container");
+ _jPanel1.remove(_container1);
+ } });
+ // Assert.assertNull(glWindow1.getParent());
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ _jFrame1.dispose();
+ } });
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ glWindow1.invalidate();
+ //Assert.assertEquals(false, glWindow1.isValid());
+ }
+
+ @Test
+ public void testWindowParenting05ReparentAWTWinHopFrame2Frame() throws InterruptedException, InvocationTargetException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ /**
+ * JFrame . JPanel . Container . NewtCanvasAWT . GLWindow
+ */
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ Assert.assertNotNull(glWindow1);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+ glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy");
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+ Animator animator1 = new Animator(glWindow1);
+ animator1.start();
+ final GLWindow _glWindow1 = glWindow1;
+ final GLRunnable _glRunnable = new GLRunnableDummy();
+ Thread disturbanceThread = new Thread(new Runnable() {
+ public void run() {
+ System.out.println("$");
+ while(true)
+ {
+ try {
+ _glWindow1.invoke(true, _glRunnable);
+ Thread.yield();
+ } catch (Throwable t) {}
+ }
+ }
+ });
+ disturbanceThread.start();
+
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
+ Assert.assertNotNull(newtCanvasAWT);
+ Assert.assertEquals(false, glWindow1.isVisible());
+ Assert.assertEquals(false, glWindow1.isNativeValid());
+ Assert.assertNull(glWindow1.getParent());
+
+ Container container1 = new Container();
+ container1.setLayout(new BorderLayout());
+ container1.add(new Button("north"), BorderLayout.NORTH);
+ container1.add(new Button("south"), BorderLayout.SOUTH);
+ container1.add(new Button("east"), BorderLayout.EAST);
+ container1.add(new Button("west"), BorderLayout.WEST);
+ container1.add(newtCanvasAWT, BorderLayout.CENTER);
+
+ JPanel jPanel1 = new JPanel();
+ jPanel1.setLayout(new BorderLayout());
+ jPanel1.add(new Button("north"), BorderLayout.NORTH);
+ jPanel1.add(new Button("south"), BorderLayout.SOUTH);
+ jPanel1.add(new Button("east"), BorderLayout.EAST);
+ jPanel1.add(new Button("west"), BorderLayout.WEST);
+ jPanel1.add(container1, BorderLayout.CENTER);
+
+ JFrame jFrame1 = new JFrame("Swing Parent JFrame");
+ // jFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ jFrame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event!
+ jFrame1.setContentPane(jPanel1);
+ jFrame1.setLocation(0, 0);
+ jFrame1.setSize(width, height);
+ jFrame1.setVisible(true); // from here on, we need to run modifications on EDT
+
+ JPanel jPanel2 = new JPanel();
+ jPanel2.setLayout(new BorderLayout());
+ jPanel2.add(new Button("north"), BorderLayout.NORTH);
+ jPanel2.add(new Button("south"), BorderLayout.SOUTH);
+ jPanel2.add(new Button("east"), BorderLayout.EAST);
+ jPanel2.add(new Button("west"), BorderLayout.WEST);
+
+ JFrame jFrame2 = new JFrame("Swing Parent JFrame");
+ // jFrame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ jFrame2.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event!
+ jFrame2.setContentPane(jPanel2);
+ jFrame2.setLocation(640, 480);
+ jFrame2.setSize(width, height);
+ jFrame2.setVisible(true); // from here on, we need to run modifications on EDT
+
+ final NewtCanvasAWT _newtCanvasAWT = newtCanvasAWT;
+ final JFrame _jFrame1 = jFrame1;
+ final JPanel _jPanel1 = jPanel1;
+ final Container _container1 = container1;
+ final JFrame _jFrame2 = jFrame2;
+ final JPanel _jPanel2 = jPanel2;
+
+ // visible test
+ Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParent());
+
+ int state = 0;
+ while(animator1.isAnimating() && animator1.getDuration()<3*durationPerTest) {
+ Thread.sleep(durationPerTest);
+ switch(state) {
+ case 0:
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ _container1.remove(_newtCanvasAWT);
+ _jPanel2.add(_newtCanvasAWT, BorderLayout.CENTER);
+ } });
+ break;
+ case 1:
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ _jPanel2.remove(_newtCanvasAWT);
+ _container1.add(_newtCanvasAWT, BorderLayout.CENTER);
+ } });
+ break;
+ }
+ state++;
+ }
+
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ _jFrame1.setVisible(false);
+ _jFrame2.setVisible(false);
+ } });
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ _jFrame1.dispose();
+ _jFrame2.dispose();
+ } });
+ Assert.assertEquals(true, glWindow1.isValid());
+
+ glWindow1.invalidate();
+ //Assert.assertEquals(false, glWindow1.isValid());
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ Window window = glWindow.getWindow();
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ } else if(args[i].equals("-wait")) {
+ waitReparent = atoi(args[++i]);
+ }
+ }
+ System.out.println("durationPerTest "+durationPerTest);
+ System.out.println("waitReparent "+waitReparent);
+ String tstname = TestParenting01cSwingAWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02AWT.java
new file mode 100644
index 000000000..20388e295
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02AWT.java
@@ -0,0 +1,267 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt.parenting;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import java.awt.Button;
+import java.awt.BorderLayout;
+import java.awt.Canvas;
+import java.awt.Frame;
+
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import com.jogamp.newt.awt.NewtCanvasAWT;
+
+import java.io.IOException;
+
+import com.jogamp.opengl.test.junit.util.*;
+import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquare;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestParenting02AWT extends UITestCase {
+ static int width, height;
+ static long durationPerTest = 500;
+ static long waitReparent = 300;
+ static boolean verbose = false;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ }
+
+ @Test
+ public void testWindowParenting01NewtChildOnAWTParentLayouted() throws InterruptedException {
+ runNewtChildOnAWTParent(true, false);
+ }
+
+ @Test
+ public void testWindowParenting02NewtChildOnAWTParentLayoutedDef() throws InterruptedException {
+ runNewtChildOnAWTParent(true, true);
+ }
+
+ @Test
+ public void testWindowParenting03NewtChildOnAWTParentDirect() throws InterruptedException {
+ runNewtChildOnAWTParent(false, false);
+ }
+
+ @Test
+ public void testWindowParenting04NewtChildOnAWTParentDirectDef() throws InterruptedException {
+ runNewtChildOnAWTParent(false, true);
+ }
+
+ public void runNewtChildOnAWTParent(boolean useLayout, boolean deferredPeer) throws InterruptedException {
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ // setup NEWT GLWindow ..
+ GLWindow glWindow = GLWindow.create(new GLCapabilities(null));
+ Assert.assertNotNull(glWindow);
+ glWindow.setTitle("NEWT - CHILD");
+ glWindow.addKeyListener(new TraceKeyAdapter(new KeyAction(eventFifo)));
+ glWindow.addWindowListener(new TraceWindowAdapter(new WindowAction(eventFifo)));
+ GLEventListener demo = new Gears();
+ setDemoFields(demo, glWindow, false);
+ glWindow.addGLEventListener(demo);
+
+ // attach NEWT GLWindow to AWT Canvas
+ NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow);
+ Assert.assertNotNull(newtCanvasAWT);
+ Assert.assertEquals(false, glWindow.isVisible());
+ Assert.assertEquals(false, glWindow.isNativeValid());
+ Assert.assertNull(glWindow.getParent());
+
+ Frame frame = new Frame("AWT Parent Frame");
+ Assert.assertNotNull(frame);
+ if(useLayout) {
+ frame.setLayout(new BorderLayout());
+ frame.add(new Button("North"), BorderLayout.NORTH);
+ frame.add(new Button("South"), BorderLayout.SOUTH);
+ frame.add(new Button("East"), BorderLayout.EAST);
+ frame.add(new Button("West"), BorderLayout.WEST);
+ if(!deferredPeer) {
+ frame.add(newtCanvasAWT, BorderLayout.CENTER);
+ }
+ } else {
+ if(!deferredPeer) {
+ frame.add(newtCanvasAWT);
+ }
+ }
+
+ frame.setSize(width, height);
+
+ frame.setVisible(true);
+ // X11: true, Windows: false - Assert.assertEquals(true, glWindow.isVisible());
+
+ if(deferredPeer) {
+ if(useLayout) {
+ frame.add(newtCanvasAWT, BorderLayout.CENTER);
+ } else {
+ frame.add(newtCanvasAWT);
+ }
+ }
+
+ // Since it is not defined when AWT's addNotify call happen
+ // we just have to wait for it in this junit test
+ // because we have assertions on the state.
+ // Regular application shall not need to do that.
+ do {
+ Thread.yield();
+ // 1st display .. creation
+ glWindow.display();
+ } while(!glWindow.isNativeValid()) ;
+
+ Assert.assertEquals(true, glWindow.isNativeValid());
+ Assert.assertNotNull(glWindow.getParent());
+ if(verbose) {
+ System.out.println("+++++++++++++++++++ 1st ADDED");
+ }
+ Thread.sleep(waitReparent);
+
+ if(useLayout) {
+ // test some fancy re-layout ..
+ frame.remove(newtCanvasAWT);
+ Assert.assertEquals(false, glWindow.isVisible());
+ Assert.assertEquals(true, glWindow.isNativeValid());
+ Assert.assertNull(glWindow.getParent());
+ if(verbose) {
+ System.out.println("+++++++++++++++++++ REMOVED!");
+ }
+ Thread.sleep(waitReparent);
+
+ // should recreate properly ..
+ frame.add(newtCanvasAWT, BorderLayout.CENTER);
+ glWindow.display();
+ Assert.assertEquals(true, glWindow.isVisible());
+ Assert.assertEquals(true, glWindow.isNativeValid());
+ Assert.assertNotNull(glWindow.getParent());
+ if(verbose) {
+ System.out.println("+++++++++++++++++++ 2nd ADDED");
+ }
+ Thread.sleep(waitReparent);
+ }
+
+ long duration = durationPerTest;
+ long step = 20;
+ NEWTEvent event;
+ boolean shouldQuit = false;
+
+ while (duration>0 && !shouldQuit) {
+ glWindow.display();
+ Thread.sleep(step);
+ duration -= step;
+
+ while( null != ( event = (NEWTEvent) eventFifo.get() ) ) {
+ Window source = (Window) event.getSource();
+ if(event instanceof KeyEvent) {
+ KeyEvent keyEvent = (KeyEvent) event;
+ switch(keyEvent.getKeyChar()) {
+ case 'q':
+ shouldQuit = true;
+ break;
+ case 'f':
+ source.setFullscreen(!source.isFullscreen());
+ break;
+ }
+ }
+ }
+ }
+ if(verbose) {
+ System.out.println("+++++++++++++++++++ END");
+ }
+ Thread.sleep(waitReparent);
+
+ glWindow.invalidate();
+ if(useLayout) {
+ frame.remove(newtCanvasAWT);
+ }
+ frame.dispose();
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ Window window = glWindow.getWindow();
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ verbose = true;
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ } else if(args[i].equals("-wait")) {
+ waitReparent = atoi(args[++i]);
+ }
+ }
+ String tstname = TestParenting02AWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02NEWT.java
new file mode 100644
index 000000000..b9bd2d93d
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02NEWT.java
@@ -0,0 +1,235 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+
+package com.jogamp.opengl.test.junit.newt.parenting;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+import javax.media.nativewindow.*;
+
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+
+import java.io.IOException;
+
+import com.jogamp.opengl.test.junit.util.*;
+import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquare;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestParenting02NEWT extends UITestCase {
+ static int width, height;
+ static long durationPerTest = 500;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ width = 640;
+ height = 480;
+ }
+
+ static Window createWindow(Screen screen, Capabilities caps) {
+ Assert.assertNotNull(caps);
+ Window window = NewtFactory.createWindow(screen, caps) ;
+ Assert.assertNotNull(window);
+ return window;
+ }
+
+ static Window createWindow(NativeWindow parent, Capabilities caps) {
+ Assert.assertNotNull(caps);
+ Window window = NewtFactory.createWindow(parent, caps);
+ window.setUndecorated(true);
+ Assert.assertNotNull(window);
+ return window;
+ }
+
+ static void destroyWindow(Display display, Screen screen, Window window, GLWindow glWindow) {
+ if(null!=glWindow) {
+ glWindow.destroy();
+ }
+ if(null!=window) {
+ window.destroy();
+ }
+ if(null!=screen) {
+ screen.destroy();
+ }
+ if(null!=display) {
+ display.destroy();
+ }
+ }
+
+ @Test
+ public void testWindowParenting01NewtOnNewtParentChildDraw() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(null);
+ Assert.assertNotNull(caps);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+
+ int x = 1;
+ int y = 1;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ Window window1 = createWindow(screen, caps);
+ Assert.assertNotNull(window1);
+ GLWindow glWindow1 = GLWindow.create(window1);
+ Assert.assertNotNull(glWindow1);
+ glWindow1.setSize(width, height);
+ Assert.assertEquals(width,glWindow1.getWidth());
+ Assert.assertEquals(height,glWindow1.getHeight());
+ glWindow1.setTitle("testWindowParenting01NewtOnNewtParentChildDraw - PARENT");
+ glWindow1.setPosition(x,y);
+ glWindow1.addKeyListener(new TraceKeyAdapter(new KeyAction(eventFifo)));
+ glWindow1.addWindowListener(new TraceWindowAdapter());
+
+ GLEventListener demo1 = new RedSquare();
+ setDemoFields(demo1, window1, glWindow1, false);
+ // glWindow1.addGLEventListener(demo1);
+
+ glWindow1.setVisible(true);
+ CapabilitiesImmutable capsChosen = glWindow1.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities();
+ Assert.assertNotNull(capsChosen);
+ Assert.assertTrue(capsChosen.isOnscreen()==true);
+
+ Window window2 = createWindow(window1, caps);
+ Assert.assertNotNull(window2);
+ GLWindow glWindow2 = GLWindow.create(window2);
+ Assert.assertNotNull(glWindow2);
+ glWindow2.setSize(width/2, height/2);
+ //Assert.assertEquals(width/2,glWindow2.getWidth());
+ //Assert.assertEquals(height/2,glWindow2.getHeight());
+ glWindow2.setTitle("testWindowParenting01NewtOnNewtParentChildDraw - CHILD");
+ glWindow2.setPosition(glWindow1.getWidth()/2, glWindow1.getHeight()/2);
+ glWindow2.addKeyListener(new TraceKeyAdapter(new KeyAction(eventFifo)));
+ glWindow2.addWindowListener(new TraceWindowAdapter(new WindowAction(eventFifo)));
+ // glWindow2.addMouseListener(new TraceMouseAdapter());
+
+ GLEventListener demo2 = new Gears();
+ setDemoFields(demo2, window2, glWindow2, false);
+ // glWindow2.addGLEventListener(demo2);
+
+ glWindow2.setVisible(true);
+ capsChosen = glWindow2.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities();
+ Assert.assertNotNull(capsChosen);
+ Assert.assertTrue(capsChosen.isOnscreen()==true);
+
+ glWindow1.addGLEventListener(demo1);
+ glWindow2.addGLEventListener(demo2);
+
+ boolean shouldQuit = false;
+ long duration = durationPerTest;
+ long step = 20;
+ NEWTEvent event;
+
+ while (duration>0 && !shouldQuit) {
+ glWindow1.display();
+ glWindow2.display();
+ Thread.sleep(step);
+ duration -= step;
+ x += 1;
+ y += 1;
+ glWindow1.setPosition(x,y);
+ glWindow2.setPosition(glWindow1.getWidth()/2,glWindow1.getHeight()/2-y);
+
+ while( null != ( event = (NEWTEvent) eventFifo.get() ) ) {
+ Window source = (Window) event.getSource();
+ if(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY == event.getEventType()) {
+ shouldQuit = true;
+ } else if(event instanceof KeyEvent) {
+ KeyEvent keyEvent = (KeyEvent) event;
+ switch(keyEvent.getKeyChar()) {
+ case 'q':
+ shouldQuit = true;
+ break;
+ case 'f':
+ source.setFullscreen(!source.isFullscreen());
+ break;
+ }
+ }
+ }
+ }
+ destroyWindow(null, null, window2, glWindow2);
+ destroyWindow(display, screen, window1, glWindow1);
+ }
+
+ public static void setDemoFields(GLEventListener demo, Window window, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(window);
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ String tstname = TestParenting02NEWT.class.getName();
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java
new file mode 100644
index 000000000..7da30cf18
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java
@@ -0,0 +1,203 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt.parenting;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import java.awt.Button;
+import java.awt.BorderLayout;
+import java.awt.Canvas;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.Label;
+
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.FPSAnimator;
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import com.jogamp.newt.awt.NewtCanvasAWT;
+
+import java.io.IOException;
+
+import com.jogamp.opengl.test.junit.util.*;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestParenting03AWT extends UITestCase {
+ static Dimension size;
+ static long durationPerTest = 400;
+ static long waitAdd2nd = 200;
+ static GLCapabilities glCaps;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ size = new Dimension(400,200);
+ glCaps = new GLCapabilities(null);
+ glCaps.setAlphaBits(8);
+ glCaps.setBackgroundOpaque(false);
+ }
+
+ @Test
+ public void testWindowParenting1AWTOneNewtChild01() throws InterruptedException, InvocationTargetException {
+ testWindowParenting1AWTOneNewtChild();
+ }
+
+ public void testWindowParenting1AWTOneNewtChild() throws InterruptedException, InvocationTargetException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ glWindow1.enablePerfLog(true);
+ glWindow1.setUndecorated(true);
+ NewtCanvasAWT newtCanvasAWT1 = new NewtCanvasAWT(glWindow1);
+ newtCanvasAWT1.setPreferredSize(size);
+
+ GLEventListener demo1 = new Gears(1);
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+ final NewtCanvasAWT f_newtCanvasAWT1 = newtCanvasAWT1;
+ final GLWindow f_glWindow1 = glWindow1;
+ glWindow1.addKeyListener(new KeyAdapter() {
+ public void keyTyped(KeyEvent e) {
+ if(e.getKeyChar()=='d') {
+ f_glWindow1.setUndecorated(!f_glWindow1.isUndecorated());
+ } else if(e.getKeyChar()=='f') {
+ f_glWindow1.setFullscreen(!f_glWindow1.isFullscreen());
+ } else if(e.getKeyChar()=='r') {
+ if(f_glWindow1.getParent()==null) {
+ System.err.println("XXX glWin1 to home");
+ f_glWindow1.reparentWindow(f_newtCanvasAWT1.getNativeWindow());
+ } else {
+ System.err.println("XXX glWin1 to TOP");
+ f_glWindow1.reparentWindow(null);
+ }
+ }
+ }
+ });
+ GLAnimatorControl animator1 = new Animator(glWindow1);
+ animator1.start();
+
+ Container cont1 = new Container();
+ cont1.setLayout(new BorderLayout());
+ cont1.add(newtCanvasAWT1, BorderLayout.CENTER);
+ cont1.setVisible(true);
+ final Container f_cont1 = cont1;
+
+ Frame frame1 = new Frame("AWT Parent Frame");
+ frame1.setLayout(new BorderLayout());
+ frame1.add(cont1, BorderLayout.EAST);
+ frame1.add(new Label("center"), BorderLayout.CENTER);
+ frame1.setLocation(0, 0);
+ frame1.setSize((int)size.getWidth(), (int)size.getHeight());
+ final Frame f_frame1 = frame1;
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ f_frame1.pack();
+ f_frame1.setVisible(true);
+ }});
+
+ Assert.assertEquals(newtCanvasAWT1.getNativeWindow(),glWindow1.getParent());
+ Assert.assertEquals(true, animator1.isAnimating());
+ Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertNotNull(animator1.getThread());
+
+ Thread.sleep(durationPerTest);
+
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+ Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertEquals(null, animator1.getThread());
+
+ frame1.dispose();
+ glWindow1.invalidate();
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ Window window = glWindow.getWindow();
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ } else if(args[i].equals("-wait")) {
+ waitAdd2nd = atoi(args[++i]);
+ }
+ }
+ String tstname = TestParenting03AWT.class.getName();
+ /*
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); */
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03bAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03bAWT.java
new file mode 100644
index 000000000..34d95d8ee
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03bAWT.java
@@ -0,0 +1,258 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt.parenting;
+
+import java.lang.reflect.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import java.awt.Button;
+import java.awt.BorderLayout;
+import java.awt.Canvas;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.Label;
+
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.FPSAnimator;
+import com.jogamp.newt.*;
+import com.jogamp.newt.event.*;
+import com.jogamp.newt.opengl.*;
+import com.jogamp.newt.awt.NewtCanvasAWT;
+
+import java.io.IOException;
+
+import com.jogamp.opengl.test.junit.util.*;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.gears.Gears;
+
+public class TestParenting03bAWT extends UITestCase {
+ static Dimension size;
+ static long durationPerTest = 800;
+ static long waitAdd2nd = 500;
+ static GLCapabilities glCaps;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ size = new Dimension(400,200);
+ glCaps = new GLCapabilities(null);
+ }
+
+ @Test
+ public void testWindowParenting1AWTTwoNewtChilds01() throws InterruptedException, InvocationTargetException {
+ testWindowParenting1AWTTwoNewtChilds();
+ }
+
+ public void testWindowParenting1AWTTwoNewtChilds() throws InterruptedException, InvocationTargetException {
+ int x = 0;
+ int y = 0;
+
+ NEWTEventFiFo eventFifo = new NEWTEventFiFo();
+
+ GLWindow glWindow1 = GLWindow.create(glCaps);
+ glWindow1.enablePerfLog(true);
+ glWindow1.setUndecorated(true);
+ NewtCanvasAWT newtCanvasAWT1 = new NewtCanvasAWT(glWindow1);
+ newtCanvasAWT1.setPreferredSize(size);
+
+ GLEventListener demo1 = new Gears(1);
+ setDemoFields(demo1, glWindow1, false);
+ glWindow1.addGLEventListener(demo1);
+ final NewtCanvasAWT f_newtCanvasAWT1 = newtCanvasAWT1;
+ final GLWindow f_glWindow1 = glWindow1;
+ glWindow1.addKeyListener(new KeyAdapter() {
+ public void keyTyped(KeyEvent e) {
+ if(e.getKeyChar()=='d') {
+ f_glWindow1.setUndecorated(!f_glWindow1.isUndecorated());
+ } else if(e.getKeyChar()=='f') {
+ f_glWindow1.setFullscreen(!f_glWindow1.isFullscreen());
+ } else if(e.getKeyChar()=='r') {
+ if(f_glWindow1.getParent()==null) {
+ System.err.println("XXX glWin1 to home");
+ f_glWindow1.reparentWindow(f_newtCanvasAWT1.getNativeWindow());
+ } else {
+ System.err.println("XXX glWin1 to TOP");
+ f_glWindow1.reparentWindow(null);
+ }
+ }
+ }
+ });
+ GLAnimatorControl animator1 = new Animator(glWindow1);
+ animator1.start();
+
+ GLWindow glWindow2 = GLWindow.create(glCaps);
+ glWindow2.enablePerfLog(true);
+ glWindow2.setUndecorated(true);
+ NewtCanvasAWT newtCanvasAWT2 = new NewtCanvasAWT(glWindow2);
+ newtCanvasAWT2.setPreferredSize(size);
+
+ GLEventListener demo2 = new Gears(1);
+ setDemoFields(demo2, glWindow2, false);
+ glWindow2.addGLEventListener(demo2);
+ final NewtCanvasAWT f_newtCanvasAWT2 = newtCanvasAWT2;
+ final GLWindow f_glWindow2 = glWindow2;
+ glWindow2.addKeyListener(new KeyAdapter() {
+ public void keyTyped(KeyEvent e) {
+ if(e.getKeyChar()=='d') {
+ f_glWindow2.setUndecorated(!f_glWindow2.isUndecorated());
+ } else if(e.getKeyChar()=='f') {
+ f_glWindow2.setFullscreen(!f_glWindow2.isFullscreen());
+ } else if(e.getKeyChar()=='r') {
+ if(f_glWindow2.getParent()==null) {
+ System.err.println("XXX glWin2 to home");
+ f_glWindow2.reparentWindow(f_newtCanvasAWT2.getNativeWindow());
+ } else {
+ System.err.println("XXX glWin2 to TOP");
+ f_glWindow2.reparentWindow(null);
+ }
+ }
+ }
+ });
+ GLAnimatorControl animator2 = new Animator(glWindow2);
+ animator2.start();
+
+ Container cont1 = new Container();
+ cont1.setLayout(new BorderLayout());
+ cont1.add(newtCanvasAWT1, BorderLayout.CENTER);
+ cont1.setVisible(true);
+ final Container f_cont1 = cont1;
+
+ Container cont2 = new Container();
+ cont2.setLayout(new BorderLayout());
+ cont2.add(newtCanvasAWT2, BorderLayout.CENTER);
+ cont2.setVisible(true);
+ final Container f_cont2 = cont2;
+
+ Frame frame1 = new Frame("AWT Parent Frame");
+ frame1.setLayout(new BorderLayout());
+ frame1.add(cont1, BorderLayout.EAST);
+ frame1.add(new Label("center"), BorderLayout.CENTER);
+ frame1.setLocation(0, 0);
+ frame1.setSize((int)size.getWidth()*2, (int)size.getHeight()*2);
+ final Frame f_frame1 = frame1;
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ f_frame1.pack();
+ f_frame1.setVisible(true);
+ }});
+
+ Assert.assertEquals(newtCanvasAWT1.getNativeWindow(),glWindow1.getParent());
+ Assert.assertEquals(newtCanvasAWT2.getNativeWindow(),glWindow2.getParent());
+
+ Assert.assertEquals(true, animator1.isAnimating());
+ Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertNotNull(animator1.getThread());
+
+ Assert.assertEquals(true, animator2.isAnimating());
+ Assert.assertEquals(false, animator2.isPaused());
+ Assert.assertNotNull(animator2.getThread());
+
+ Thread.sleep(waitAdd2nd);
+
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ f_frame1.add(f_cont2, BorderLayout.WEST);
+ f_frame1.pack();
+ }});
+
+ Thread.sleep(durationPerTest);
+
+ animator1.stop();
+ Assert.assertEquals(false, animator1.isAnimating());
+ Assert.assertEquals(false, animator1.isPaused());
+ Assert.assertEquals(null, animator1.getThread());
+
+ animator2.stop();
+ Assert.assertEquals(false, animator2.isAnimating());
+ Assert.assertEquals(false, animator2.isPaused());
+ Assert.assertEquals(null, animator2.getThread());
+
+ frame1.dispose();
+ glWindow1.invalidate();
+ glWindow2.invalidate();
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ Window window = glWindow.getWindow();
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ } else if(args[i].equals("-wait")) {
+ waitAdd2nd = atoi(args[++i]);
+ }
+ }
+ String tstname = TestParenting03bAWT.class.getName();
+ /*
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); */
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/WindowAction.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/WindowAction.java
new file mode 100644
index 000000000..bb4008e57
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/WindowAction.java
@@ -0,0 +1,44 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.newt.parenting;
+
+import com.jogamp.newt.event.*;
+
+class WindowAction extends WindowAdapter {
+ NEWTEventFiFo eventFifo;
+
+ public WindowAction(NEWTEventFiFo eventFifo) {
+ this.eventFifo = eventFifo;
+ }
+
+ public void windowDestroyNotify(WindowEvent e) {
+ eventFifo.put(e);
+ }
+}
+
diff --git a/src/test/com/jogamp/opengl/test/junit/util/AWTFocusAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/AWTFocusAdapter.java
new file mode 100644
index 000000000..a24127772
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/util/AWTFocusAdapter.java
@@ -0,0 +1,73 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.util;
+
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+
+public class AWTFocusAdapter implements EventCountAdapter, FocusListener {
+
+ String prefix;
+ int focusGained;
+ boolean wasTemporary;
+
+ public AWTFocusAdapter(String prefix) {
+ this.prefix = prefix;
+ reset();
+ }
+
+ /** @return the balance of focus gained/lost, ie should be 0 or 1 */
+ public int getCount() {
+ return focusGained;
+ }
+
+ public void reset() {
+ focusGained = 0;
+ wasTemporary = false;
+ }
+
+ /** @return true, if the last change was temporary */
+ public boolean getWasTemporary() {
+ return wasTemporary;
+ }
+
+ @Override
+ public void focusGained(FocusEvent e) {
+ ++focusGained;
+ wasTemporary = e.isTemporary();
+ System.err.println("FOCUS AWT GAINED "+(wasTemporary?"TEMP":"PERM")+" ["+focusGained+"]: "+prefix+", "+e);
+ }
+
+ @Override
+ public void focusLost(FocusEvent e) {
+ --focusGained;
+ wasTemporary = e.isTemporary();
+ System.err.println("FOCUS AWT LOST "+(wasTemporary?"TEMP":"PERM")+" ["+focusGained+"]: "+prefix+", "+e);
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/util/AWTKeyAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/AWTKeyAdapter.java
new file mode 100644
index 000000000..ed09ecd8c
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/util/AWTKeyAdapter.java
@@ -0,0 +1,54 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.util;
+
+public class AWTKeyAdapter extends java.awt.event.KeyAdapter implements EventCountAdapter {
+
+ String prefix;
+ int keyTyped;
+
+ public AWTKeyAdapter(String prefix) {
+ this.prefix = prefix;
+ reset();
+ }
+
+ public int getCount() {
+ return keyTyped;
+ }
+
+ public void reset() {
+ keyTyped = 0;
+ }
+
+ public void keyTyped(java.awt.event.KeyEvent e) {
+ ++keyTyped;
+ System.err.println("KEY AWT TYPED ["+keyTyped+"]: "+prefix+", "+e);
+ }
+}
+
diff --git a/src/test/com/jogamp/opengl/test/junit/util/AWTMouseAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/AWTMouseAdapter.java
new file mode 100644
index 000000000..7fa201512
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/util/AWTMouseAdapter.java
@@ -0,0 +1,53 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.util;
+
+public class AWTMouseAdapter extends java.awt.event.MouseAdapter implements EventCountAdapter {
+ String prefix;
+ int mouseClicked;
+
+ public AWTMouseAdapter(String prefix) {
+ this.prefix = prefix;
+ reset();
+ }
+
+ public int getCount() {
+ return mouseClicked;
+ }
+
+ public void reset() {
+ mouseClicked = 0;
+ }
+
+ public void mouseClicked(java.awt.event.MouseEvent e) {
+ mouseClicked+=e.getClickCount();
+ System.err.println("MOUSE AWT CLICKED ["+mouseClicked+"]: "+prefix+", "+e);
+ }
+}
+
diff --git a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java
new file mode 100644
index 000000000..61aa95bf8
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java
@@ -0,0 +1,338 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.util;
+
+import java.lang.reflect.InvocationTargetException;
+import java.awt.AWTException;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.KeyboardFocusManager;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.Robot;
+import java.awt.Window;
+import java.awt.event.InputEvent;
+import javax.swing.JFrame;
+
+public class AWTRobotUtil {
+
+ public static int TIME_OUT = 1000; // 1s
+ public static int ROBOT_DELAY = 50; // ms
+ public static int POLL_DIVIDER = 20; // TO/20
+
+ public static Point getCenterLocation(Object obj, boolean frameTitlebar)
+ throws InterruptedException, InvocationTargetException {
+ Component comp = null;
+ com.jogamp.newt.Window win = null;
+
+ if(obj instanceof com.jogamp.newt.Window) {
+ win = (com.jogamp.newt.Window) obj;
+ } else if(obj instanceof Component) {
+ comp = (Component) obj;
+ } else {
+ throw new RuntimeException("Neither AWT nor NEWT: "+obj);
+ }
+
+ int x0, y0;
+ if(null!=comp) {
+ Point p0 = comp.getLocationOnScreen();
+ Rectangle r0 = comp.getBounds();
+ if( frameTitlebar && comp instanceof JFrame ) {
+ JFrame jFrame = (JFrame) comp;
+ Container cont = jFrame.getContentPane();
+ Point p1 = cont.getLocationOnScreen();
+ int dx = (int) ( r0.getWidth() / 2.0 + .5 );
+ int dy = (int) ( ( p1.getY() - p0.getY() ) / 2.0 + .5 );
+ x0 = (int) ( p0.getX() + dx + .5 ) ;
+ y0 = (int) ( p0.getY() + dy + .5 ) ;
+ } else {
+ x0 = (int) ( p0.getX() + r0.getWidth() / 2.0 + .5 ) ;
+ y0 = (int) ( p0.getY() + r0.getHeight() / 2.0 + .5 ) ;
+ }
+ } else {
+ javax.media.nativewindow.util.Point p0 = win.getLocationOnScreen(null);
+ p0.translate(win.getWidth()/2, win.getHeight()/2);
+ x0 = p0.getX();
+ y0 = p0.getY();
+ }
+
+ return new Point(x0, y0);
+ }
+
+ /**
+ * toFront, call setVisible(true) and toFront(),
+ * after positioning the mouse in the middle of the window via robot.
+ * If the given robot is null, a new one is created (waitForIdle=true).
+ *
+ * @return True if the Window became the global focused Window within TIME_OUT
+ */
+ public static boolean toFront(Robot robot, Window window)
+ throws AWTException, InterruptedException, InvocationTargetException {
+
+ if(null == robot) {
+ robot = new Robot();
+ robot.setAutoWaitForIdle(true);
+ }
+ Point p0 = getCenterLocation(window, false);
+ System.err.println("robot pos: "+p0);
+ robot.mouseMove( (int) p0.getX(), (int) p0.getY() );
+ robot.delay(ROBOT_DELAY);
+
+ final Window f_window = window;
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ f_window.setVisible(true);
+ f_window.toFront();
+ f_window.requestFocus();
+ }});
+ robot.delay(ROBOT_DELAY);
+
+ KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
+ int wait;
+ for (wait=0; wait<POLL_DIVIDER && window != kfm.getFocusedWindow(); wait++) {
+ Thread.sleep(TIME_OUT/POLL_DIVIDER);
+ }
+ return wait<POLL_DIVIDER;
+ }
+
+ /**
+ * centerMouse
+ */
+ public static void centerMouse(Robot robot, Object obj)
+ throws AWTException, InterruptedException, InvocationTargetException {
+ Component comp = null;
+ com.jogamp.newt.Window win = null;
+
+ if(null == robot) {
+ robot = new Robot();
+ robot.setAutoWaitForIdle(true);
+ }
+
+ if(obj instanceof com.jogamp.newt.Window) {
+ win = (com.jogamp.newt.Window) obj;
+ } else if(obj instanceof Component) {
+ comp = (Component) obj;
+ } else {
+ throw new RuntimeException("Neither AWT nor NEWT: "+obj);
+ }
+
+ Point p0 = getCenterLocation(obj, false);
+ System.err.println("robot pos: "+p0);
+
+ robot.mouseMove( (int) p0.getX(), (int) p0.getY() );
+ robot.delay(ROBOT_DELAY);
+ }
+
+ /**
+ * requestFocus, if robot is valid, use mouse operation,
+ * otherwise programatic, ie call requestFocus
+ */
+ public static void requestFocus(Robot robot, Object obj)
+ throws AWTException, InterruptedException, InvocationTargetException {
+ Component comp = null;
+ com.jogamp.newt.Window win = null;
+
+ if(obj instanceof com.jogamp.newt.Window) {
+ win = (com.jogamp.newt.Window) obj;
+ } else if(obj instanceof Component) {
+ comp = (Component) obj;
+ } else {
+ throw new RuntimeException("Neither AWT nor NEWT: "+obj);
+ }
+
+ if(null == robot) {
+ if(null!=comp) {
+ final Component f_comp = comp;
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ f_comp.requestFocus();
+ }});
+ } else {
+ win.requestFocus();
+ }
+ return;
+ }
+
+ centerMouse(robot, obj);
+
+ robot.delay(ROBOT_DELAY);
+ robot.mousePress(InputEvent.BUTTON1_MASK);
+ robot.delay(ROBOT_DELAY);
+ robot.mouseRelease(InputEvent.BUTTON1_MASK);
+ robot.delay(ROBOT_DELAY);
+ }
+
+ /**
+ *
+ * @return True if the Window became the global focused Window within TIME_OUT
+ */
+ public static boolean waitForFocus(Object obj) throws InterruptedException {
+ int wait;
+ if(obj instanceof Component) {
+ Component comp = (Component) obj;
+ KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
+ for (wait=0; wait<POLL_DIVIDER && comp != kfm.getPermanentFocusOwner(); wait++) {
+ Thread.sleep(TIME_OUT/POLL_DIVIDER);
+ }
+ } else if(obj instanceof com.jogamp.newt.Window) {
+ com.jogamp.newt.Window win = (com.jogamp.newt.Window) obj;
+ for (wait=0; wait<POLL_DIVIDER && !win.hasFocus(); wait++) {
+ Thread.sleep(TIME_OUT/POLL_DIVIDER);
+ }
+ } else {
+ throw new RuntimeException("Neither AWT nor NEWT: "+obj);
+ }
+ return wait<POLL_DIVIDER;
+ }
+
+ /**
+ *
+ * @return True if the Window became the global focused Window within TIME_OUT
+ */
+ public static boolean waitForFocus(Object obj, int gainT0, EventCountAdapter gain,
+ int lostT0, EventCountAdapter lost) throws InterruptedException {
+ if(!waitForFocus(obj)) {
+ return false;
+ }
+ int wait;
+ for (wait=0; wait<POLL_DIVIDER; wait++) {
+ int gainT1 = gain.getCount();
+ int lostT1 = (null!=lost) ? lost.getCount() : -1;
+ if(gainT1-gainT0==1 && lostT1-lostT0==-1) {
+ return true;
+ }
+ Thread.sleep(TIME_OUT/POLL_DIVIDER);
+ }
+ return false;
+ }
+
+ public static boolean requestFocusAndWait(Robot robot, Object requestFocus, Object waitForFocus)
+ throws AWTException, InterruptedException, InvocationTargetException {
+
+ requestFocus(robot, requestFocus);
+ return waitForFocus(waitForFocus);
+ }
+
+ public static boolean requestFocusAndWait(Robot robot, Object requestFocus, Object waitForFocus,
+ EventCountAdapter gain, EventCountAdapter lost)
+ throws AWTException, InterruptedException, InvocationTargetException {
+
+ int gainT0 = gain.getCount();
+ int lostT0 = (null!=lost) ? lost.getCount() : 0;
+
+ requestFocus(robot, requestFocus);
+ return waitForFocus(waitForFocus, gainT0, gain, lostT0, lost);
+ }
+
+ /**
+ * @param keyTypedCounter shall return the number of keys typed (press + release)
+ * @return True if typeCount keys within TIME_OUT has been received
+ */
+ public static int testKeyType(Robot robot, int typeCount, Object obj, EventCountAdapter keyTypedCounter)
+ throws AWTException, InterruptedException, InvocationTargetException {
+ Component comp = null;
+ com.jogamp.newt.Window win = null;
+
+ if(null == robot) {
+ robot = new Robot();
+ robot.setAutoWaitForIdle(true);
+ }
+
+ centerMouse(robot, obj);
+
+ int c0 = keyTypedCounter.getCount();
+
+ for(int i=0; i<typeCount; i++) {
+ robot.keyPress(java.awt.event.KeyEvent.VK_A);
+ robot.delay(ROBOT_DELAY);
+ robot.keyRelease(java.awt.event.KeyEvent.VK_A);
+ robot.delay(ROBOT_DELAY);
+ }
+
+ // Wait for the key events to be processed.
+ int wait;
+ for (wait=0; wait<POLL_DIVIDER && (keyTypedCounter.getCount()-c0)<typeCount; wait++) {
+ Thread.sleep(TIME_OUT/POLL_DIVIDER);
+ }
+ return keyTypedCounter.getCount()-c0;
+ }
+
+ /**
+ * @param mouseButton ie InputEvent.BUTTON1_MASK
+ * @param clickCount ie 1, or 2
+ * @return True if the desired clickCount within TIME_OUT has been received
+ */
+ public static int testMouseClick(Robot robot, int mouseButton, int clickCount,
+ Object obj, EventCountAdapter mouseClickCounter)
+ throws AWTException, InterruptedException, InvocationTargetException {
+
+ if(null == robot) {
+ robot = new Robot();
+ robot.setAutoWaitForIdle(true);
+ }
+
+ final int clickTO = com.jogamp.newt.event.MouseEvent.getClickTimeout();
+
+ centerMouse(robot, obj);
+
+ robot.delay(2*clickTO);
+
+ int c0 = mouseClickCounter.getCount();
+
+ for(int i=0; i<clickCount; i++) {
+ robot.mousePress(mouseButton);
+ robot.delay(clickTO/4);
+ robot.mouseRelease(mouseButton);
+ robot.delay(clickTO/4);
+ }
+
+ // Wait for the key events to be processed.
+ int wait;
+ for (wait=0; wait<POLL_DIVIDER && (mouseClickCounter.getCount()-c0)<clickCount; wait++) {
+ Thread.sleep(TIME_OUT/POLL_DIVIDER);
+ }
+ return mouseClickCounter.getCount()-c0;
+ }
+
+ /**
+ *
+ * @return True if the EventCountAdapter became the desired value within TIME_OUT
+ */
+ public static boolean waitForCount(int desired, EventCountAdapter eca) throws InterruptedException {
+ for (int wait=0; wait<POLL_DIVIDER; wait++) {
+ if( eca.getCount() == desired ) {
+ return true;
+ }
+ Thread.sleep(TIME_OUT/POLL_DIVIDER);
+ }
+ return false;
+ }
+
+}
+
diff --git a/src/test/com/jogamp/opengl/test/junit/util/DumpGLInfo.java b/src/test/com/jogamp/opengl/test/junit/util/DumpGLInfo.java
new file mode 100644
index 000000000..d31bf3421
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/util/DumpGLInfo.java
@@ -0,0 +1,51 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.util;
+
+
+import javax.media.opengl.*;
+import com.jogamp.opengl.JoglVersion;
+
+
+public class DumpGLInfo implements GLEventListener {
+
+ public void init(GLAutoDrawable drawable) {
+ GL gl = drawable.getGL();
+ System.err.println(JoglVersion.getInstance().getGLInfo(gl, null));
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/util/EventCountAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/EventCountAdapter.java
new file mode 100644
index 000000000..105d2503e
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/util/EventCountAdapter.java
@@ -0,0 +1,36 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.util;
+
+public interface EventCountAdapter {
+
+ int getCount();
+ void reset();
+}
+
diff --git a/src/test/com/jogamp/opengl/test/junit/util/EventCountAdapterUtil.java b/src/test/com/jogamp/opengl/test/junit/util/EventCountAdapterUtil.java
new file mode 100644
index 000000000..d919d7cb6
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/util/EventCountAdapterUtil.java
@@ -0,0 +1,49 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.util;
+
+import java.util.List;
+import java.util.Iterator;
+
+public abstract class EventCountAdapterUtil {
+
+ public static void reset(EventCountAdapter[] adapters) {
+ for(int i=0; i<adapters.length; i++) {
+ adapters[i].reset();
+ }
+ }
+
+ public static void reset(List/*<EventCountAdapter>*/ adapters) {
+ for(Iterator i = adapters.iterator(); i.hasNext(); ) {
+ EventCountAdapter adapter = (EventCountAdapter) i.next();
+ adapter.reset();
+ }
+ }
+}
+
diff --git a/src/test/com/jogamp/opengl/test/junit/util/GLSLSimpleProgram.java b/src/test/com/jogamp/opengl/test/junit/util/GLSLSimpleProgram.java
new file mode 100644
index 000000000..bcafc02f7
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/util/GLSLSimpleProgram.java
@@ -0,0 +1,121 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.util;
+
+import com.jogamp.opengl.util.glsl.ShaderUtil;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2ES2;
+import org.junit.Assert;
+
+public class GLSLSimpleProgram {
+ private int shaderProgram;
+ private int vertShader;
+ private int fragShader;
+
+ private GLSLSimpleProgram(int shaderProgram, int vertShader, int fragShader) {
+ this.shaderProgram = shaderProgram;
+ this.vertShader = vertShader;
+ this.fragShader = fragShader;
+ }
+
+ public static GLSLSimpleProgram create(GL2ES2 gl, String vertShaderCode, String fragShaderCode, boolean link) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintStream pbaos = new PrintStream(baos);
+
+ int vertShader = gl.glCreateShader(GL2ES2.GL_VERTEX_SHADER);
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+
+ int fragShader = gl.glCreateShader(GL2ES2.GL_FRAGMENT_SHADER);
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+
+ String[] vlines = new String[] { vertShaderCode };
+ int[] vlengths = new int[] { vlines[0].length() };
+ gl.glShaderSource(vertShader, vlines.length, vlines, vlengths, 0);
+ gl.glCompileShader(vertShader);
+ if(!ShaderUtil.isShaderStatusValid(gl, vertShader, gl.GL_COMPILE_STATUS, pbaos)) {
+ System.out.println("getShader:postCompile vertShader: "+baos.toString());
+ Assert.assertTrue(false);
+ }
+ pbaos.flush(); baos.reset();
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+
+
+ String[] flines = new String[] { fragShaderCode };
+ int[] flengths = new int[] { flines[0].length() };
+ gl.glShaderSource(fragShader, flines.length, flines, flengths, 0);
+ gl.glCompileShader(fragShader);
+ if(!ShaderUtil.isShaderStatusValid(gl, fragShader, gl.GL_COMPILE_STATUS, pbaos)) {
+ System.out.println("getShader:postCompile fragShader: "+baos.toString());
+ Assert.assertTrue(false);
+ }
+ pbaos.flush(); baos.reset();
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+
+ int shaderProgram = gl.glCreateProgram();
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ gl.glAttachShader(shaderProgram, vertShader);
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ gl.glAttachShader(shaderProgram, fragShader);
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+
+ if(link) {
+ gl.glLinkProgram(shaderProgram);
+ if(!ShaderUtil.isProgramValid(gl, shaderProgram, pbaos)) {
+ System.out.println("Error (GLSL link error): "+baos.toString());
+ Assert.assertTrue(false);
+ }
+ }
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ GLSLSimpleProgram res = new GLSLSimpleProgram(shaderProgram, vertShader, fragShader);
+ return res;
+ }
+
+ public void release(GL2ES2 gl) {
+ gl.glUseProgram(0);
+ gl.glDetachShader(shaderProgram, vertShader);
+ gl.glDeleteShader(vertShader);
+ gl.glDetachShader(shaderProgram, fragShader);
+ gl.glDeleteShader(fragShader);
+ gl.glDeleteProgram(shaderProgram);
+ }
+
+ public int getFragShader() {
+ return fragShader;
+ }
+
+ public int getShaderProgram() {
+ return shaderProgram;
+ }
+
+ public int getVertShader() {
+ return vertShader;
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java b/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java
new file mode 100644
index 000000000..506fe2d97
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java
@@ -0,0 +1,63 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+
+package com.jogamp.opengl.test.junit.util;
+
+import java.lang.reflect.*;
+
+public class MiscUtils {
+ public static int atoi(String str, int def) {
+ try {
+ return Integer.parseInt(str);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ return def;
+ }
+
+ public static boolean setFieldIfExists(Object instance, String fieldName, Object value) {
+ try {
+ Field f = instance.getClass().getField(fieldName);
+ if(value instanceof Boolean || f.getType().isInstance(value)) {
+ f.set(instance, value);
+ return true;
+ } else {
+ System.out.println(instance.getClass()+" '"+fieldName+"' field not assignable with "+value.getClass()+", it's a: "+f.getType());
+ }
+ } catch (IllegalAccessException ex) {
+ throw new RuntimeException(ex);
+ } catch (NoSuchFieldException nsfe) {
+ // OK - throw new RuntimeException(instance.getClass()+" has no '"+fieldName+"' field", nsfe);
+ }
+ return false;
+ }
+}
+
+
+
diff --git a/src/test/com/jogamp/opengl/test/junit/util/NEWTFocusAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/NEWTFocusAdapter.java
new file mode 100644
index 000000000..9ee74aeff
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/util/NEWTFocusAdapter.java
@@ -0,0 +1,64 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.util;
+
+import com.jogamp.newt.event.WindowAdapter;
+import com.jogamp.newt.event.WindowEvent;
+
+public class NEWTFocusAdapter extends WindowAdapter implements EventCountAdapter {
+
+ String prefix;
+ int focusGained;
+
+ public NEWTFocusAdapter(String prefix) {
+ this.prefix = prefix;
+ reset();
+ }
+
+ public int getCount() {
+ return focusGained;
+ }
+
+ public void reset() {
+ focusGained = 0;
+ }
+
+ @Override
+ public void windowGainedFocus(WindowEvent e) {
+ ++focusGained;
+ System.err.println("FOCUS NEWT GAINED ["+focusGained+"]: "+prefix+", "+e);
+ }
+
+ @Override
+ public void windowLostFocus(WindowEvent e) {
+ --focusGained;
+ System.err.println("FOCUS NEWT LOST ["+focusGained+"]: "+prefix+", "+e);
+ }
+}
+
diff --git a/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyAdapter.java
new file mode 100644
index 000000000..ba1a2f3f5
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/util/NEWTKeyAdapter.java
@@ -0,0 +1,58 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.util;
+
+import com.jogamp.newt.event.KeyAdapter;
+import com.jogamp.newt.event.KeyEvent;
+
+public class NEWTKeyAdapter extends KeyAdapter implements EventCountAdapter {
+
+ String prefix;
+ int keyTyped;
+
+ public NEWTKeyAdapter(String prefix) {
+ this.prefix = prefix;
+ reset();
+ }
+
+ public int getCount() {
+ return keyTyped;
+ }
+
+ public void reset() {
+ keyTyped = 0;
+ }
+
+ @Override
+ public void keyTyped(KeyEvent e) {
+ ++keyTyped;
+ System.err.println("KEY NEWT TYPED ["+keyTyped+"]: "+prefix+", "+e);
+ }
+}
+
diff --git a/src/test/com/jogamp/opengl/test/junit/util/NEWTMouseAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/NEWTMouseAdapter.java
new file mode 100644
index 000000000..617d951ec
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/util/NEWTMouseAdapter.java
@@ -0,0 +1,57 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.util;
+
+import com.jogamp.newt.event.MouseAdapter;
+import com.jogamp.newt.event.MouseEvent;
+
+public class NEWTMouseAdapter extends MouseAdapter implements EventCountAdapter {
+
+ String prefix;
+ int mouseClicked;
+
+ public NEWTMouseAdapter(String prefix) {
+ this.prefix = prefix;
+ reset();
+ }
+
+ public int getCount() {
+ return mouseClicked;
+ }
+
+ public void reset() {
+ mouseClicked = 0;
+ }
+
+ public void mouseClicked(MouseEvent e) {
+ mouseClicked+=e.getClickCount();
+ System.err.println("MOUSE NEWT CLICKED ["+mouseClicked+"]: "+prefix+", "+e);
+ }
+}
+
diff --git a/src/test/com/jogamp/opengl/test/junit/util/QuitAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/QuitAdapter.java
new file mode 100644
index 000000000..77996bf1e
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/util/QuitAdapter.java
@@ -0,0 +1,52 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.util;
+
+import com.jogamp.newt.event.*;
+
+public class QuitAdapter extends WindowAdapter implements WindowListener, KeyListener {
+ boolean shouldQuit = false;
+
+ public boolean shouldQuit() { return shouldQuit; }
+
+ public void windowDestroyNotify(WindowEvent e) {
+ System.out.println("QUIT Window "+Thread.currentThread());
+ shouldQuit = true;
+ }
+
+ public void keyTyped(KeyEvent e) {
+ if(e.getKeyChar()=='q') {
+ System.out.println("QUIT Key "+Thread.currentThread());
+ shouldQuit = true;
+ }
+ }
+ public void keyPressed(KeyEvent e) {}
+ public void keyReleased(KeyEvent e) {}
+}
+
diff --git a/src/test/com/jogamp/opengl/test/junit/util/SingletonInstance.java b/src/test/com/jogamp/opengl/test/junit/util/SingletonInstance.java
new file mode 100644
index 000000000..7e3b9ebc0
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/util/SingletonInstance.java
@@ -0,0 +1,143 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.channels.FileLock;
+
+public class SingletonInstance {
+
+ static final boolean DEBUG = true;
+ static final String temp_file_path;
+
+ static {
+ String s = null;
+ try {
+ File tmpFile = File.createTempFile("TEST", "tst");
+ String absTmpFile = tmpFile.getCanonicalPath();
+ tmpFile.delete();
+ s = absTmpFile.substring(0, absTmpFile.lastIndexOf(File.separator));
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ temp_file_path = s;
+ }
+
+ public static String getCanonicalTempPath() {
+ return temp_file_path;
+ }
+
+ public static String getCanonicalTempLockFilePath(String basename) {
+ return getCanonicalTempPath() + File.separator + basename;
+ }
+
+ public SingletonInstance(String lockFileBasename) {
+ this.file = new File ( getCanonicalTempLockFilePath ( lockFileBasename ) );
+ }
+
+ public SingletonInstance(File lockFile) {
+ this.file = lockFile ;
+ }
+
+ public synchronized void lock(long timeout_ms, long poll_ms) {
+ long i=0;
+ try {
+ do {
+ if(tryLock()) {
+ return;
+ }
+ if(DEBUG && 0==i) {
+ System.err.println("Wait for lock " + file);
+ }
+ i++;
+ Thread.sleep(poll_ms);
+ } while ( i < timeout_ms / poll_ms ) ;
+ } catch ( InterruptedException ie ) {
+ throw new RuntimeException(ie);
+ }
+ throw new RuntimeException("SingletonInstance couldn't get lock within "+timeout_ms+"ms");
+ }
+
+ public synchronized boolean tryLock() {
+ try {
+ randomAccessFile = new RandomAccessFile(file, "rw");
+ fileLock = randomAccessFile.getChannel().tryLock();
+
+ if (fileLock != null) {
+ //final File f_file = file;
+ //final RandomAccessFile f_randomAccessFile = randomAccessFile;
+ //final FileLock f_fileLock = fileLock;
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ public void run() {
+ unlock();
+ }
+ });
+ locked = true;
+ if(DEBUG) {
+ System.err.println("Locked " + file);
+ }
+ return true;
+ }
+ } catch (Exception e) {
+ System.err.println("Unable to create and/or lock file: " + file);
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ public synchronized boolean unlock() {
+ if(locked) {
+ try {
+ fileLock.release();
+ randomAccessFile.close();
+ file.delete();
+ return true;
+ } catch (Exception e) {
+ System.err.println("Unable to remove lock file: " + file);
+ e.printStackTrace();
+ } finally {
+ fileLock = null;
+ randomAccessFile = null;
+ locked = false;
+ }
+ }
+ return false;
+ }
+
+ public synchronized boolean isLocked() {
+ return locked;
+ }
+
+ File file = null;
+ RandomAccessFile randomAccessFile = null;
+ FileLock fileLock = null;
+ boolean locked = false;
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java b/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java
new file mode 100644
index 000000000..b01ba1be9
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java
@@ -0,0 +1,72 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.util;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.AfterClass;
+
+
+public abstract class UITestCase {
+
+ public static final String SINGLE_INSTANCE_LOCK_FILE = "UITestCase.lock";
+
+ static SingletonInstance singletonInstance;
+
+ protected SingletonInstance getSingletonInstance() {
+ return singletonInstance;
+ }
+
+ @BeforeClass
+ public static void oneTimeSetUp() {
+ // one-time initialization code
+ singletonInstance = new SingletonInstance(SINGLE_INSTANCE_LOCK_FILE);
+ singletonInstance.lock(3*60*1000, 100); // wait up to 3 min, poll every 100ms
+ }
+
+ @AfterClass
+ public static void oneTimeTearDown() {
+ // one-time cleanup code
+ System.gc(); // force cleanup
+ singletonInstance.unlock();
+ }
+
+ @Before
+ public void setUp() {
+ System.err.println("++++ UITestCase.setUp: "+getClass().getName());
+ }
+
+ @After
+ public void tearDown() {
+ System.err.println("++++ UITestCase.tearDown: "+getClass().getName());
+ }
+
+}
+