summaryrefslogtreecommitdiffstats
path: root/src/junit/com/jogamp/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/junit/com/jogamp/test')
-rwxr-xr-xsrc/junit/com/jogamp/test/junit/jogl/demos/es1/RedSquare.java158
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/Gears.java306
-rwxr-xr-xsrc/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java143
-rwxr-xr-xsrc/junit/com/jogamp/test/junit/jogl/offscreen/ReadBuffer2File.java76
-rwxr-xr-xsrc/junit/com/jogamp/test/junit/jogl/offscreen/ReadBuffer2Screen.java188
-rwxr-xr-xsrc/junit/com/jogamp/test/junit/jogl/offscreen/ReadBufferBase.java91
-rwxr-xr-xsrc/junit/com/jogamp/test/junit/jogl/offscreen/ReadBufferUtil.java110
-rwxr-xr-xsrc/junit/com/jogamp/test/junit/jogl/offscreen/Surface2File.java78
-rwxr-xr-xsrc/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java86
-rwxr-xr-xsrc/junit/com/jogamp/test/junit/jogl/offscreen/WindowUtilNEWT.java138
-rwxr-xr-xsrc/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java (renamed from src/junit/com/jogamp/test/junit/jogl/awt/texture/Texture1.java)8
-rw-r--r--src/junit/com/jogamp/test/junit/util/MiscUtils.java64
12 files changed, 1442 insertions, 4 deletions
diff --git a/src/junit/com/jogamp/test/junit/jogl/demos/es1/RedSquare.java b/src/junit/com/jogamp/test/junit/jogl/demos/es1/RedSquare.java
new file mode 100755
index 000000000..82da095b9
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/demos/es1/RedSquare.java
@@ -0,0 +1,158 @@
+package com.jogamp.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;
+
+ long startTime = 0;
+ long curTime = 0;
+
+ GLU glu = null;
+
+ public RedSquare() {
+ }
+
+ // 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) {
+ 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);
+
+ 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) {
+ 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) {
+ GL2ES1 gl = drawable.getGL().getGL2ES1();
+ 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;
+ System.out.println(Thread.currentThread()+" RedSquare.dispose: FIN");
+ }
+
+ public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/Gears.java b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/Gears.java
new file mode 100644
index 000000000..135efd341
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/Gears.java
@@ -0,0 +1,306 @@
+
+package com.jogamp.test.junit.jogl.demos.gl2.gears;
+
+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;
+
+/**
+ * Gears.java <BR>
+ * author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel) <P>
+ *
+ * This version is equal to Brian Paul's version 1.2 1999/10/21
+ */
+
+public class Gears implements GLEventListener /* , MouseListener, MouseMotionListener */ {
+ private float view_rotx = 20.0f, view_roty = 30.0f, view_rotz = 0.0f;
+ private int gear1, gear2, gear3;
+ private float angle = 0.0f;
+
+ private int prevMouseX, prevMouseY;
+ private boolean mouseRButtonDown = false;
+
+ public void init(GLAutoDrawable drawable) {
+ // Use debug pipeline
+ // drawable.setGL(new DebugGL(drawable.getGL()));
+
+ GL2 gl = drawable.getGL().getGL2();
+
+ System.err.println("INIT GL IS: " + gl.getClass().getName());
+
+ System.err.println("Chosen GLCapabilities: " + drawable.getChosenGLCapabilities());
+
+ gl.setSwapInterval(1);
+
+ float pos[] = { 5.0f, 5.0f, 10.0f, 0.0f };
+ float red[] = { 0.8f, 0.1f, 0.0f, 1.0f };
+ float green[] = { 0.0f, 0.8f, 0.2f, 1.0f };
+ float blue[] = { 0.2f, 0.2f, 1.0f, 1.0f };
+
+ 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 */
+ 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();
+
+ 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();
+
+ 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();
+
+ gl.glEnable(GL2.GL_NORMALIZE);
+
+ /**
+ if (drawable instanceof AWTGLAutoDrawable) {
+ AWTGLAutoDrawable awtDrawable = (AWTGLAutoDrawable) drawable;
+ awtDrawable.addMouseListener(this);
+ awtDrawable.addMouseMotionListener(this);
+ } */
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ GL2 gl = drawable.getGL().getGL2();
+
+ float h = (float)height / (float)width;
+
+ gl.glMatrixMode(GL2.GL_PROJECTION);
+
+ System.err.println("GL_VENDOR: " + gl.glGetString(GL2.GL_VENDOR));
+ System.err.println("GL_RENDERER: " + gl.glGetString(GL2.GL_RENDERER));
+ System.err.println("GL_VERSION: " + gl.glGetString(GL2.GL_VERSION));
+ 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.out.println("Gears.dispose: "+drawable);
+ }
+
+ 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();
+
+ /**
+ // Special handling for the case where the GLJPanel is translucent
+ // and wants to be composited with other Java 2D content
+ if ((drawable instanceof GLJPanel) &&
+ !((GLJPanel) drawable).isOpaque() &&
+ ((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 void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
+
+ 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();
+ }
+
+ /***
+ // Methods required for the implementation of MouseListener
+ public void mouseEntered(MouseEvent e) {}
+ public void mouseExited(MouseEvent e) {}
+
+ 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 mouseClicked(MouseEvent e) {}
+
+ // Methods required for the implementation of MouseMotionListener
+ public void mouseDragged(MouseEvent e) {
+ int x = e.getX();
+ int y = e.getY();
+ Dimension size = e.getComponent().getSize();
+
+ float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)size.width);
+ float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)size.height);
+
+ prevMouseX = x;
+ prevMouseY = y;
+
+ view_rotx += thetaX;
+ view_roty += thetaY;
+ }
+
+ public void mouseMoved(MouseEvent e) {}
+ */
+}
diff --git a/src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java b/src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java
new file mode 100755
index 000000000..6c812ba18
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2010 Sven Gothel. 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 Sven Gothel 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
+ * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+package com.jogamp.test.junit.jogl.drawable;
+
+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.Test;
+
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+
+import com.jogamp.newt.*;
+import com.jogamp.newt.opengl.*;
+
+public class TestDrawable01NEWT {
+ static GLProfile glp;
+ static int width, height;
+ GLCapabilities caps;
+ Window window;
+ GLDrawable drawable;
+ GLContext context;
+
+ @BeforeClass
+ public static void initClass() {
+ glp = GLProfile.getDefault();
+ width = 640;
+ height = 480;
+ }
+
+ @Before
+ public void initTest() {
+ caps = new GLCapabilities(glp);
+ }
+
+ void createWindow(boolean onscreen, boolean pbuffer, boolean undecorated) {
+ caps.setOnscreen(onscreen);
+ caps.setPBuffer(!onscreen && pbuffer);
+ caps.setDoubleBuffered(!onscreen);
+ System.out.println("**********************************************************");
+ System.out.println("**********************************************************");
+ System.out.println("Requested: "+caps);
+
+ //
+ // Create native windowing resources .. X11/Win/OSX
+ //
+ Display display = NewtFactory.createDisplay(null); // local display
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ window = NewtFactory.createWindow(screen, caps, onscreen && undecorated);
+ window.setSize(width, height);
+ window.setVisible(true);
+ System.out.println("**********************************************************");
+ System.out.println("**********************************************************");
+ 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();
+
+ GLDrawableFactory factory = GLDrawableFactory.getFactory(glCaps.getGLProfile());
+ System.out.println(factory);
+ drawable = factory.createGLDrawable(window);
+ System.out.println("**********************************************************");
+ System.out.println("**********************************************************");
+ System.out.println("Pre: "+drawable);
+ drawable.setRealized(true);
+ System.out.println("**********************************************************");
+ System.out.println("**********************************************************");
+ System.out.println("Post: "+drawable);
+ context = drawable.createContext(null);
+ System.out.println(context);
+
+ System.out.println("**********************************************************");
+ System.out.println("**********************************************************");
+ System.out.println("Final: "+window);
+ }
+
+ void destroyWindow() {
+ context.destroy();
+ drawable.setRealized(false);
+ window.destroy(true); // incl screen + display
+ }
+
+ @Test
+ public void testOnScreenDecorated() {
+ createWindow(true, false, false);
+ try {
+ Thread.sleep(1000); // 1000 ms
+ } catch (Exception e) {}
+ destroyWindow();
+ }
+
+ @Test
+ public void testOnScreenUndecorated() {
+ createWindow(true, false, true);
+ try {
+ Thread.sleep(1000); // 1000 ms
+ } catch (Exception e) {}
+ destroyWindow();
+ }
+
+ public static void main(String args[]) {
+ org.junit.runner.JUnitCore.main(TestDrawable01NEWT.class.getName());
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBuffer2File.java b/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBuffer2File.java
new file mode 100755
index 000000000..2b32f720e
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBuffer2File.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2010 Sven Gothel. 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 Sven Gothel 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
+ * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+package com.jogamp.test.junit.jogl.offscreen;
+
+import java.nio.*;
+import javax.media.opengl.*;
+
+import com.jogamp.opengl.util.texture.TextureData;
+import com.jogamp.opengl.util.texture.TextureIO;
+import java.io.File;
+import java.io.IOException;
+
+import javax.media.nativewindow.*;
+
+public class ReadBuffer2File extends ReadBufferBase {
+
+ public ReadBuffer2File (GLDrawable externalRead) {
+ super(externalRead);
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ super.dispose(drawable);
+ }
+
+ int shotNum=0;
+
+ void copyTextureData2File() {
+ if(!readBufferUtil.isValid()) return;
+
+ try {
+ File file = File.createTempFile("shot"+shotNum+"-", ".ppm");
+ TextureIO.write(readBufferUtil.getTextureData(), file);
+ if(0==shotNum) {
+ System.out.println("Wrote: "+file.getAbsolutePath()+", ...");
+ }
+ shotNum++;
+ } catch (IOException ioe) { ioe.printStackTrace(); }
+ readBufferUtil.rewindPixelBuffer();
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ super.display(drawable);
+ copyTextureData2File();
+ }
+}
+
diff --git a/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBuffer2Screen.java b/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBuffer2Screen.java
new file mode 100755
index 000000000..1166cc1e5
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBuffer2Screen.java
@@ -0,0 +1,188 @@
+/*
+ * Copyright (c) 2010 Sven Gothel. 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 Sven Gothel 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
+ * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+package com.jogamp.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);
+ }
+
+ 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);
+ }
+
+ 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());
+ }
+ }
+
+ 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);
+ }
+ }
+
+ 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/junit/com/jogamp/test/junit/jogl/offscreen/ReadBufferBase.java b/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBufferBase.java
new file mode 100755
index 000000000..597b21782
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBufferBase.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2010 Sven Gothel. 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 Sven Gothel 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
+ * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+package com.jogamp.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) {e.printStackTrace();}
+ }
+
+ if(glTrace) {
+ try {
+ _gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", null, _gl, new Object[] { System.err } ) );
+ } catch (Exception e) {e.printStackTrace();}
+ }
+
+ System.out.println(_gl);
+
+ _gl.getContext().setGLDrawableRead(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/junit/com/jogamp/test/junit/jogl/offscreen/ReadBufferUtil.java b/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBufferUtil.java
new file mode 100755
index 000000000..d409093f4
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/offscreen/ReadBufferUtil.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2010 Sven Gothel. 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 Sven Gothel 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
+ * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+package com.jogamp.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) {
+ e.printStackTrace();
+ readTextureData = null;
+ readPixelBuffer = null;
+ readPixelSizeLast = 0;
+ }
+ }
+ 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();
+ }
+ }
+
+ public void dispose() {
+ readTexture.dispose();
+ readTextureData = null;
+ readPixelBuffer.clear();
+ readPixelBuffer = null;
+ readPixelSizeLast = 0;
+ }
+
+}
+
diff --git a/src/junit/com/jogamp/test/junit/jogl/offscreen/Surface2File.java b/src/junit/com/jogamp/test/junit/jogl/offscreen/Surface2File.java
new file mode 100755
index 000000000..43e2df54c
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/offscreen/Surface2File.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2010 Sven Gothel. 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 Sven Gothel 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
+ * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+package com.jogamp.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, NativeWindow window, long when) {
+ if(updater instanceof GLDrawable) {
+ GLDrawable drawable = (GLDrawable) updater;
+ GLContext ctx = GLContext.getCurrent();
+ if(null!=ctx && ctx.getGLDrawable()==drawable) {
+ readBufferUtil.fetchOffscreenTexture(drawable, ctx.getGL());
+ surface2File("shot");
+ }
+ }
+ }
+
+ public void surface2File(String basename) {
+ if(!readBufferUtil.isValid()) return;
+
+ try {
+ File file = File.createTempFile(basename+shotNum+"-", ".ppm");
+ TextureIO.write(readBufferUtil.getTextureData(), file);
+ if(0==shotNum) {
+ System.out.println("Wrote: "+file.getAbsolutePath()+", ...");
+ }
+ shotNum++;
+ } catch (IOException ioe) { ioe.printStackTrace(); }
+ readBufferUtil.rewindPixelBuffer();
+ }
+}
+
diff --git a/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java b/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java
new file mode 100755
index 000000000..a8caafb30
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2010 Sven Gothel. 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 Sven Gothel 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
+ * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+package com.jogamp.test.junit.jogl.offscreen;
+
+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.Test;
+
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+
+import com.jogamp.newt.*;
+import com.jogamp.newt.opengl.*;
+
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+import com.jogamp.test.junit.jogl.demos.es1.RedSquare;
+
+public class TestOffscreen01NEWT {
+ int width, height;
+ GLProfile glp;
+ GLCapabilities caps;
+
+ @Before
+ public void init() {
+ glp = GLProfile.getDefault();
+ width = 640;
+ height = 480;
+ caps = new GLCapabilities(glp);
+ }
+
+ @Test
+ public void test1() {
+ if(false) {
+ GLWindow windowOffscreen = WindowUtilNEWT.createGLWindow(caps, width, height, false, true, false);
+ GLEventListener demo = new RedSquare();
+ GLWindow windowOnScreen = null;
+ WindowListener wl=null;
+ MouseListener ml=null;
+ SurfaceUpdatedListener ul=null;
+
+ WindowUtilNEWT.run(windowOffscreen, demo, windowOnScreen, wl, ml, ul, 2, true /*debug*/);
+ WindowUtilNEWT.shutdown(windowOffscreen, windowOnScreen);
+ }
+ }
+
+ public static void main(String args[]) {
+ org.junit.runner.JUnitCore.main(TestOffscreen01NEWT.class.getName());
+ }
+
+}
diff --git a/src/junit/com/jogamp/test/junit/jogl/offscreen/WindowUtilNEWT.java b/src/junit/com/jogamp/test/junit/jogl/offscreen/WindowUtilNEWT.java
new file mode 100755
index 000000000..31ee7b552
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/offscreen/WindowUtilNEWT.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2010 Sven Gothel. 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 Sven Gothel 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
+ * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+package com.jogamp.test.junit.jogl.offscreen;
+
+import com.jogamp.test.junit.util.*;
+
+import java.lang.reflect.*;
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+import com.jogamp.newt.*;
+import com.jogamp.newt.opengl.*;
+
+public class WindowUtilNEWT {
+
+ public static Window createWindow(GLCapabilities caps, int w, int h, boolean onscreen, boolean pbuffer, boolean undecorated) {
+ GLCapabilities caps2 = (GLCapabilities) caps.clone();
+ caps2.setOnscreen(onscreen);
+ caps2.setPBuffer(!onscreen && pbuffer);
+ caps2.setDoubleBuffered(!onscreen);
+
+ Display display = NewtFactory.createDisplay(null); // local display
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Window window = NewtFactory.createWindow(screen, caps2, onscreen && undecorated);
+
+ GLCapabilities glCaps = (GLCapabilities) window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities();
+
+ GLDrawableFactory factory = GLDrawableFactory.getFactory(glCaps.getGLProfile());
+ GLDrawable drawable = factory.createGLDrawable(window);
+ drawable.setRealized(true);
+ GLContext context = drawable.createContext(null);
+
+ window.setSize(w, h);
+ window.setVisible(true);
+ return window;
+ }
+
+ public static GLWindow createGLWindow(GLCapabilities caps, int w, int h, boolean onscreen, boolean pbuffer, boolean undecorated) {
+ GLCapabilities caps2 = (GLCapabilities) caps.clone();
+ caps2.setOnscreen(onscreen);
+ caps2.setPBuffer(!onscreen && pbuffer);
+ caps2.setDoubleBuffered(!onscreen);
+ GLWindow window = GLWindow.create(caps2, onscreen && undecorated);
+ window.setSize(w, h);
+ window.setVisible(true);
+ return window;
+ }
+
+ public static void run(GLWindow windowOffscreen, GLEventListener demo,
+ GLWindow windowOnScreen, WindowListener wl, MouseListener ml,
+ SurfaceUpdatedListener ul, int frames, boolean debug) {
+ try {
+ if(debug) {
+ MiscUtils.setField(demo, "glDebug", new Boolean(true));
+ MiscUtils.setField(demo, "glTrace", new Boolean(true));
+ }
+ if(!MiscUtils.setField(demo, "window", windowOffscreen)) {
+ MiscUtils.setField(demo, "glWindow", windowOffscreen);
+ }
+ 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 ) {
+ ReadBuffer2File readDemo = new ReadBuffer2File( readDrawable ) ;
+ } else {
+ ReadBuffer2Screen readDemo = new ReadBuffer2Screen( readDrawable ) ;
+ windowOnScreen.addGLEventListener(readDemo);
+ if(null!=wl) {
+ windowOffscreen.addSurfaceUpdatedListener(ul);
+ }
+ }
+
+ System.out.println("+++++++++++++++++++++++++++");
+ System.out.println(windowOffscreen);
+ System.out.println("+++++++++++++++++++++++++++");
+
+ while ( windowOffscreen.getTotalFrames() < frames) {
+ windowOffscreen.display();
+ }
+
+ } catch (GLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void shutdown(GLWindow windowOffscreen, GLWindow windowOnscreen) {
+ // Shut things down cooperatively
+ if(null!=windowOnscreen) {
+ windowOnscreen.destroy();
+ }
+ if(null!=windowOffscreen) {
+ windowOffscreen.destroy();
+ }
+ if(null!=windowOnscreen) {
+ windowOnscreen.getFactory().shutdown();
+ }
+ }
+}
diff --git a/src/junit/com/jogamp/test/junit/jogl/awt/texture/Texture1.java b/src/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java
index 6023bf87f..d83e064bf 100755
--- a/src/junit/com/jogamp/test/junit/jogl/awt/texture/Texture1.java
+++ b/src/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java
@@ -30,7 +30,7 @@
* SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
-package com.jogamp.test.junit.jogl.awt.texture;
+package com.jogamp.test.junit.jogl.texture;
import com.jogamp.test.junit.jogl.util.texture.gl2.TextureGL2ListenerDraw1;
@@ -65,7 +65,7 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-public class Texture1 {
+public class TestTexture01AWT {
Frame frame;
BufferedImage textureImage;
@@ -108,7 +108,7 @@ public class Texture1 {
animator.start();
try {
- Thread.sleep(100); // 100 ms
+ Thread.sleep(1000); // 1000 ms
} catch (Exception e) {}
animator.stop();
@@ -120,6 +120,6 @@ public class Texture1 {
}
public static void main(String args[]) {
- org.junit.runner.JUnitCore.main(Texture1.class.getName());
+ org.junit.runner.JUnitCore.main(TestTexture01AWT.class.getName());
}
}
diff --git a/src/junit/com/jogamp/test/junit/util/MiscUtils.java b/src/junit/com/jogamp/test/junit/util/MiscUtils.java
new file mode 100644
index 000000000..5114c3a84
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/util/MiscUtils.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2010 Sven Gothel. 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 Sven Gothel 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
+ * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+package com.jogamp.test.junit.util;
+
+import java.lang.reflect.*;
+
+public class MiscUtils {
+ public static int str2int(String str, int def) {
+ try {
+ return Integer.parseInt(str);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return def;
+ }
+
+ public static boolean setField(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 (NoSuchFieldException nsfe) {
+ System.out.println(instance.getClass()+" has no '"+fieldName+"' field");
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ return false;
+ }
+}
+
+
+