summaryrefslogtreecommitdiffstats
path: root/src/demo
diff options
context:
space:
mode:
Diffstat (limited to 'src/demo')
-rwxr-xr-xsrc/demo/GPURegionNewtDemo01.java167
-rw-r--r--[-rwxr-xr-x]src/demo/GPURegionNewtDemo02.java260
-rw-r--r--src/demo/GPURegionRendererListenerBase01.java53
-rw-r--r--src/demo/GPURendererListenerBase01.java (renamed from src/demo/GPUTextGLListenerBase01.java)177
-rw-r--r--src/demo/GPUTextNewtDemo01.java17
-rw-r--r--src/demo/GPUTextNewtDemo02.java15
-rw-r--r--src/demo/GPUTextRendererListenerBase01.java190
-rw-r--r--src/demo/ReadBufferUtil.java107
-rw-r--r--src/demo/Screenshot.java39
9 files changed, 613 insertions, 412 deletions
diff --git a/src/demo/GPURegionNewtDemo01.java b/src/demo/GPURegionNewtDemo01.java
index d58d4148d..676621692 100755
--- a/src/demo/GPURegionNewtDemo01.java
+++ b/src/demo/GPURegionNewtDemo01.java
@@ -32,18 +32,14 @@ import javax.media.opengl.GL;
import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
-import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import com.jogamp.graph.curve.OutlineShape;
+import com.jogamp.graph.curve.Region;
import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.geom.opengl.SVertex;
-import com.jogamp.newt.event.KeyEvent;
-import com.jogamp.newt.event.KeyListener;
-import com.jogamp.newt.event.WindowAdapter;
-import com.jogamp.newt.event.WindowEvent;
import com.jogamp.newt.opengl.GLWindow;
-import com.jogamp.opengl.util.FPSAnimator;
+import com.jogamp.opengl.util.Animator;
/** Demonstrate the rendering of multiple outlines into one region/OutlineShape
* These Outlines are not necessary connected or contained.
@@ -53,21 +49,18 @@ import com.jogamp.opengl.util.FPSAnimator;
*
*/
public class GPURegionNewtDemo01 {
- private static void create(){
- new RegionNewtWindow();
- }
- public static void main(String[] args) {
- create();
- }
-}
-
-class RegionNewtWindow {
+ static final boolean DEBUG = false;
+ static final boolean TRACE = false;
+
+ public static void main(String[] args) {
+ GPURegionNewtDemo01 test = new GPURegionNewtDemo01();
+ test.testMe();
+ }
+
RegionGLListener regionGLListener = null;
-
- public RegionNewtWindow(){
- createWindow();
- }
- private void createWindow() {
+ GLWindow window;
+
+ public void testMe() {
GLProfile.initSingleton(true);
GLProfile glp = GLProfile.getGL2ES2();
GLCapabilities caps = new GLCapabilities(glp);
@@ -75,65 +68,45 @@ class RegionNewtWindow {
caps.setSampleBuffers(true);
caps.setNumSamples(4); // 2 samples is not enough ..
System.out.println("Requested: " + caps);
- final GLWindow window = GLWindow.create(caps);
- window.setPosition(10, 10);
- window.setSize(500, 500);
- window.setTitle("GPU Curve Region Newt Demo 01 - r2t0 msaa1");
- regionGLListener = new RegionGLListener();
+
+ GLWindow w = GLWindow.create(caps);
+ w.setPosition(10, 10);
+ w.setSize(800, 400);
+ w.setTitle("GPU Curve Region Newt Demo 01 - r2t0 msaa1");
+
+ regionGLListener = createRegionRendererListener(w);
+
window.addGLEventListener(regionGLListener);
+ window.enablePerfLog(true);
window.setVisible(true);
- window.addKeyListener(new KeyListener() {
- public void keyPressed(KeyEvent arg0) {
- if(arg0.getKeyCode() == KeyEvent.VK_1){
- regionGLListener.zoomIn();
- }
- else if(arg0.getKeyCode() == KeyEvent.VK_2){
- regionGLListener.zoomOut();
- }
- else if(arg0.getKeyCode() == KeyEvent.VK_UP){
- regionGLListener.move(0, -1);
- }
- else if(arg0.getKeyCode() == KeyEvent.VK_DOWN){
- regionGLListener.move(0, 1);
- }
- else if(arg0.getKeyCode() == KeyEvent.VK_LEFT){
- regionGLListener.move(1, 0);
- }
- else if(arg0.getKeyCode() == KeyEvent.VK_RIGHT){
- regionGLListener.move(-1, 0);
- }
- else if(arg0.getKeyCode() == KeyEvent.VK_0){
- regionGLListener.rotate(1);
- }
- else if(arg0.getKeyCode() == KeyEvent.VK_9){
- regionGLListener.rotate(-1);
- }
- }
- public void keyTyped(KeyEvent arg0) {}
- public void keyReleased(KeyEvent arg0) {}
- });
-
- FPSAnimator animator = new FPSAnimator(60);
+ //FPSAnimator animator = new FPSAnimator(60);
+ Animator animator = new Animator();
animator.add(window);
- window.addWindowListener(new WindowAdapter() {
- public void windowDestroyNotify(WindowEvent arg0) {
- System.exit(0);
- };
- });
animator.start();
}
- private class RegionGLListener implements GLEventListener{
- RegionRenderer regionRenderer = null;
-
+
+ public RegionGLListener createRegionRendererListener(GLWindow w) {
+ this.window = w;
+
+ RegionGLListener l = new RegionGLListener();
+ l.attachInputListenerTo(w);
+
+ return l;
+ }
+
+ public class RegionGLListener extends GPURegionRendererListenerBase01 {
OutlineShape outlineShape = null;
- public RegionGLListener() {}
+ public RegionGLListener() {
+ super(SVertex.factory(), Region.SINGLE_PASS, DEBUG, TRACE);
+ setMatrix(-20, 00, 0f, -50, 400);
+ }
private void createTestOutline(){
float offset = 0;
- outlineShape = new OutlineShape(SVertex.factory());
+ outlineShape = new OutlineShape(getRenderer().getFactory());
outlineShape.addVertex(0.0f,-10.0f, true);
outlineShape.addVertex(15.0f,-10.0f, true);
outlineShape.addVertex(10.0f,5.0f, false);
@@ -169,64 +142,38 @@ class RegionNewtWindow {
}
public void init(GLAutoDrawable drawable) {
- GL2ES2 gl = drawable.getGL().getGL2ES2();
+ super.init(drawable);
+
+ GL2ES2 gl = drawable.getGL().getGL2ES2();
+
+ final RegionRenderer regionRenderer = (RegionRenderer) getRenderer();
+
gl.setSwapInterval(1);
gl.glEnable(GL2ES2.GL_DEPTH_TEST);
- regionRenderer = new RegionRenderer(drawable.getContext());
- regionRenderer.setAlpha(1.0f);
- regionRenderer.setColor(0.0f, 0.0f, 0.0f);
+ regionRenderer.init(gl);
+ regionRenderer.setAlpha(gl, 1.0f);
+ regionRenderer.setColor(gl, 0.0f, 0.0f, 0.0f);
//gl.glSampleCoverage(0.95f, false);
//gl.glEnable(GL2GL3.GL_SAMPLE_COVERAGE); // sample coverage doesn't really make a difference to lines
//gl.glEnable(GL2GL3.GL_SAMPLE_ALPHA_TO_ONE);
MSAATool.dump(drawable);
+
createTestOutline();
}
- float ang = 0;
- float zoom = -70;
- float xTran = -20;
- float yTran = 5;
-
public void display(GLAutoDrawable drawable) {
GL2ES2 gl = drawable.getGL().getGL2ES2();
gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
- regionRenderer.resetMatrix();
- regionRenderer.translate(xTran, yTran, zoom);
- regionRenderer.rotate(ang, 0, 1, 0);
-
- try {
- regionRenderer.renderOutlineShape(outlineShape, new float[]{0,0,0});
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void reshape(GLAutoDrawable drawable, int xstart, int ystart, int width, int height){
- GL2ES2 gl = drawable.getGL().getGL2ES2();
- gl.glViewport(xstart, ystart, width, height);
-
- regionRenderer.reshape(drawable, 45.0f, (float)width / (float)height, 0.1f, 7000.0f);
- }
+ final RegionRenderer regionRenderer = (RegionRenderer) getRenderer();
+
+ regionRenderer.resetModelview(null);
+ regionRenderer.translate(null, getXTran(), getYTran(), getZoom());
+ regionRenderer.rotate(gl, getAngle(), 0, 1, 0);
- public void zoomIn(){
- zoom++;
- }
- public void zoomOut(){
- zoom--;
- }
- public void move(float x, float y){
- xTran += x;
- yTran += y;
- }
- public void rotate(float delta){
- ang+= delta;
- ang%=360;
- }
- public void dispose(GLAutoDrawable arg0) {
- regionRenderer.clearCached();
-
- }
+ regionRenderer.renderOutlineShape(gl, outlineShape, getPosition(), getTexSize());
+ }
}
}
diff --git a/src/demo/GPURegionNewtDemo02.java b/src/demo/GPURegionNewtDemo02.java
index 19889ac6e..a7b56ad42 100755..100644
--- a/src/demo/GPURegionNewtDemo02.java
+++ b/src/demo/GPURegionNewtDemo02.java
@@ -32,193 +32,145 @@ import javax.media.opengl.GL;
import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
-import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import com.jogamp.graph.curve.OutlineShape;
+import com.jogamp.graph.curve.Region;
import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.geom.opengl.SVertex;
-import com.jogamp.newt.event.KeyEvent;
-import com.jogamp.newt.event.KeyListener;
-import com.jogamp.newt.event.WindowAdapter;
-import com.jogamp.newt.event.WindowEvent;
import com.jogamp.newt.opengl.GLWindow;
-import com.jogamp.opengl.util.FPSAnimator;
+import com.jogamp.opengl.util.Animator;
/** Demonstrate the rendering of multiple OutlineShapes
* into one region
*
*/
public class GPURegionNewtDemo02 {
- private static void create(){
- new RegionsNewtWindow();
- }
- public static void main(String[] args) {
- create();
- }
-}
-
-class RegionsNewtWindow {
+ static final boolean DEBUG = false;
+ static final boolean TRACE = false;
+
+ public static void main(String[] args) {
+ GPURegionNewtDemo02 test = new GPURegionNewtDemo02();
+ test.testMe();
+ }
+
RegionGLListener regionGLListener = null;
-
- public RegionsNewtWindow(){
- createWindow();
- }
- private void createWindow() {
+ GLWindow window;
+ public void testMe() {
GLProfile.initSingleton(true);
- GLProfile glp = GLProfile.getGL2ES2();
- GLCapabilities caps = new GLCapabilities(glp);
- System.out.println("Requested: "+caps);
- final GLWindow window = GLWindow.create(caps);
- window.setPosition(10, 10);
- window.setSize(500, 500);
-
- window.setTitle("GPU Curve Region Newt Demo 02 - r2t0 msaa0");
- regionGLListener = new RegionGLListener();
- window.addGLEventListener(regionGLListener);
-
+ GLProfile glp = GLProfile.get(GLProfile.GL3);
+ GLCapabilities caps = new GLCapabilities(glp);
+ caps.setAlphaBits(4);
+ System.out.println("Requested: " + caps);
+
+ GLWindow w = GLWindow.create(caps);
+ w.setPosition(10, 10);
+ w.setSize(800, 400);
+ w.setTitle("GPU Curve Region Newt Demo 02 - r2t1 msaa0");
+
+ regionGLListener = createRegionRendererListener(w);
+ window.addGLEventListener(regionGLListener);
+
+ window.enablePerfLog(true);
window.setVisible(true);
- window.addKeyListener(new KeyListener() {
- public void keyPressed(KeyEvent arg0) {
- if(arg0.getKeyCode() == KeyEvent.VK_1){
- regionGLListener.zoomIn();
- }
- else if(arg0.getKeyCode() == KeyEvent.VK_2){
- regionGLListener.zoomOut();
- }
- else if(arg0.getKeyCode() == KeyEvent.VK_UP){
- regionGLListener.move(0, -1);
- }
- else if(arg0.getKeyCode() == KeyEvent.VK_DOWN){
- regionGLListener.move(0, 1);
- }
- else if(arg0.getKeyCode() == KeyEvent.VK_LEFT){
- regionGLListener.move(1, 0);
- }
- else if(arg0.getKeyCode() == KeyEvent.VK_RIGHT){
- regionGLListener.move(-1, 0);
- }
- else if(arg0.getKeyCode() == KeyEvent.VK_0){
- regionGLListener.rotate(1);
- }
- else if(arg0.getKeyCode() == KeyEvent.VK_9){
- regionGLListener.rotate(-1);
- }
- }
- public void keyTyped(KeyEvent arg0) {}
- public void keyReleased(KeyEvent arg0) {}
- });
-
- FPSAnimator animator = new FPSAnimator(60);
+ //FPSAnimator animator = new FPSAnimator(60);
+ Animator animator = new Animator();
animator.add(window);
- window.addWindowListener(new WindowAdapter() {
- public void windowDestroyNotify(WindowEvent arg0) {
- System.exit(0);
- };
- });
animator.start();
}
- private class RegionGLListener implements GLEventListener{
- RegionRenderer regionRenderer = null;
-
- OutlineShape[] outlineShapes = new OutlineShape[2];
+
+ public RegionGLListener createRegionRendererListener(GLWindow w) {
+ this.window = w;
+
+ RegionGLListener l = new RegionGLListener();
+ l.attachInputListenerTo(w);
+
+ return l;
+ }
+
+ public class RegionGLListener extends GPURegionRendererListenerBase01 {
+ OutlineShape[] outlineShapes = new OutlineShape[2];
- public RegionGLListener() {}
-
- private void createTestOutline(){
- float offset = 0;
- outlineShapes[0] = new OutlineShape(SVertex.factory());
- outlineShapes[0].addVertex(0.0f,-10.0f,true);
- outlineShapes[0].addVertex(15.0f,-10.0f, true);
- outlineShapes[0].addVertex(10.0f,5.0f, false);
- outlineShapes[0].addVertex(15.0f,10.0f, true);
- outlineShapes[0].addVertex(6.0f,15.0f, false);
- outlineShapes[0].addVertex(5.0f,8.0f, false);
- outlineShapes[0].addVertex(0.0f,10.0f,true);
- outlineShapes[0].closeLastOutline();
- outlineShapes[0].addEmptyOutline();
- outlineShapes[0].addVertex(5.0f,-5.0f,true);
- outlineShapes[0].addVertex(10.0f,-5.0f, false);
- outlineShapes[0].addVertex(10.0f,0.0f, true);
- outlineShapes[0].addVertex(5.0f,0.0f, false);
- outlineShapes[0].closeLastOutline();
-
- /** Same shape as above but without any off-curve vertices */
- outlineShapes[1] = new OutlineShape(SVertex.factory());
- offset = 30;
- outlineShapes[1].addVertex(offset+0.0f,-10.0f, true);
- outlineShapes[1].addVertex(offset+17.0f,-10.0f, true);
- outlineShapes[1].addVertex(offset+11.0f,5.0f, true);
- outlineShapes[1].addVertex(offset+16.0f,10.0f, true);
- outlineShapes[1].addVertex(offset+7.0f,15.0f, true);
- outlineShapes[1].addVertex(offset+6.0f,8.0f, true);
- outlineShapes[1].addVertex(offset+0.0f,10.0f, true);
- outlineShapes[1].closeLastOutline();
- outlineShapes[1].addEmptyOutline();
- outlineShapes[1].addVertex(offset+5.0f,0.0f, true);
- outlineShapes[1].addVertex(offset+5.0f,-5.0f, true);
- outlineShapes[1].addVertex(offset+10.0f,-5.0f, true);
- outlineShapes[1].addVertex(offset+10.0f,0.0f, true);
- outlineShapes[1].closeLastOutline();
+ public RegionGLListener() {
+ super(SVertex.factory(), Region.TWO_PASS, DEBUG, TRACE);
+ setMatrix(-20, 00, 0f, -50, 400);
+ //setMatrix(-20, 00, 0f, -400, 400);
+ //setMatrix(-20, 00, 0f, -400, 400);
+ //setMatrix(-20, 00, 0f, -100, 800);
}
+
+ private void createTestOutline(){
+ float offset = 0;
+ outlineShapes[0] = new OutlineShape(SVertex.factory());
+ outlineShapes[0].addVertex(0.0f,-10.0f,true);
+ outlineShapes[0].addVertex(15.0f,-10.0f, true);
+ outlineShapes[0].addVertex(10.0f,5.0f, false);
+ outlineShapes[0].addVertex(15.0f,10.0f, true);
+ outlineShapes[0].addVertex(6.0f,15.0f, false);
+ outlineShapes[0].addVertex(5.0f,8.0f, false);
+ outlineShapes[0].addVertex(0.0f,10.0f,true);
+ outlineShapes[0].closeLastOutline();
+ outlineShapes[0].addEmptyOutline();
+ outlineShapes[0].addVertex(5.0f,-5.0f,true);
+ outlineShapes[0].addVertex(10.0f,-5.0f, false);
+ outlineShapes[0].addVertex(10.0f,0.0f, true);
+ outlineShapes[0].addVertex(5.0f,0.0f, false);
+ outlineShapes[0].closeLastOutline();
+
+ /** Same shape as above but without any off-curve vertices */
+ outlineShapes[1] = new OutlineShape(SVertex.factory());
+ offset = 30;
+ outlineShapes[1].addVertex(offset+0.0f,-10.0f, true);
+ outlineShapes[1].addVertex(offset+17.0f,-10.0f, true);
+ outlineShapes[1].addVertex(offset+11.0f,5.0f, true);
+ outlineShapes[1].addVertex(offset+16.0f,10.0f, true);
+ outlineShapes[1].addVertex(offset+7.0f,15.0f, true);
+ outlineShapes[1].addVertex(offset+6.0f,8.0f, true);
+ outlineShapes[1].addVertex(offset+0.0f,10.0f, true);
+ outlineShapes[1].closeLastOutline();
+ outlineShapes[1].addEmptyOutline();
+ outlineShapes[1].addVertex(offset+5.0f,0.0f, true);
+ outlineShapes[1].addVertex(offset+5.0f,-5.0f, true);
+ outlineShapes[1].addVertex(offset+10.0f,-5.0f, true);
+ outlineShapes[1].addVertex(offset+10.0f,0.0f, true);
+ outlineShapes[1].closeLastOutline();
+ }
public void init(GLAutoDrawable drawable) {
- GL2ES2 gl = drawable.getGL().getGL2ES2();
+ super.init(drawable);
+
+ GL2ES2 gl = drawable.getGL().getGL2ES2();
+
+ final RegionRenderer regionRenderer = (RegionRenderer) getRenderer();
+
gl.setSwapInterval(1);
gl.glEnable(GL2ES2.GL_DEPTH_TEST);
- regionRenderer = new RegionRenderer(drawable.getContext());
- regionRenderer.setAlpha(1.0f);
- regionRenderer.setColor(0.0f, 0.0f, 0.0f);
+ regionRenderer.init(gl);
+ regionRenderer.setAlpha(gl, 1.0f);
+ regionRenderer.setColor(gl, 0.0f, 0.0f, 0.0f);
+ //gl.glSampleCoverage(0.95f, false);
+ //gl.glEnable(GL2GL3.GL_SAMPLE_COVERAGE); // sample coverage doesn't really make a difference to lines
+ //gl.glEnable(GL2GL3.GL_SAMPLE_ALPHA_TO_ONE);
MSAATool.dump(drawable);
+
createTestOutline();
}
- float ang = 0;
- float zoom = -70;
- float xTran = -20;
- float yTran = 5;
-
public void display(GLAutoDrawable drawable) {
- GL2ES2 gl = drawable.getGL().getGL2ES2();
+ GL2ES2 gl = drawable.getGL().getGL2ES2();
- gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
- gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+ gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
- regionRenderer.resetMatrix();
- regionRenderer.translate(xTran, yTran, zoom);
- regionRenderer.rotate(ang, 0, 1, 0);
+ final RegionRenderer regionRenderer = (RegionRenderer) getRenderer();
+
+ regionRenderer.resetModelview(null);
+ regionRenderer.translate(null, getXTran(), getYTran(), getZoom());
+ regionRenderer.rotate(gl, getAngle(), 0, 1, 0);
- try {
- regionRenderer.renderOutlineShapes(outlineShapes, new float[]{0,0,0});
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void reshape(GLAutoDrawable drawable, int xstart, int ystart, int width, int height){
- GL2ES2 gl = drawable.getGL().getGL2ES2();
- gl.glViewport(xstart, ystart, width, height);
-
- regionRenderer.reshape(drawable, 45.0f, (float)width / (float)height, 0.1f, 7000.0f);
- }
-
- public void zoomIn(){
- zoom++;
- }
- public void zoomOut(){
- zoom--;
- }
- public void move(float x, float y){
- xTran += x;
- yTran += y;
- }
- public void rotate(float delta){
- ang+= delta;
- ang%=360;
- }
- public void dispose(GLAutoDrawable arg0) {
- regionRenderer.clearCached();
+ regionRenderer.renderOutlineShapes(gl, outlineShapes, getPosition(), getTexSize());
- }
+ }
}
}
diff --git a/src/demo/GPURegionRendererListenerBase01.java b/src/demo/GPURegionRendererListenerBase01.java
new file mode 100644
index 000000000..19742a17a
--- /dev/null
+++ b/src/demo/GPURegionRendererListenerBase01.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 demo;
+
+import jogamp.graph.curve.opengl.RegionRendererImpl01;
+
+import com.jogamp.graph.curve.OutlineShape;
+import com.jogamp.graph.geom.Vertex;
+
+/**
+ *
+ * Action Keys:
+ * - 1/2: zoom in/out
+ * - 3/4: font +/-
+ * - 6/7: 2nd pass texture size
+ * - 0/9: rotate
+ * - s: toogle draw 'font set'
+ * - f: toggle draw fps
+ * - v: toggle v-sync
+ * - space: toggle font (ubuntu/java)
+ */
+public abstract class GPURegionRendererListenerBase01 extends GPURendererListenerBase01 {
+ OutlineShape outlineShape = null;
+
+ public GPURegionRendererListenerBase01(Vertex.Factory<? extends Vertex> factory, int mode, boolean debug, boolean trace) {
+ super(new RegionRendererImpl01(factory, mode), debug, trace);
+ }
+} \ No newline at end of file
diff --git a/src/demo/GPUTextGLListenerBase01.java b/src/demo/GPURendererListenerBase01.java
index 238a733ce..ae72e6f66 100644
--- a/src/demo/GPUTextGLListenerBase01.java
+++ b/src/demo/GPURendererListenerBase01.java
@@ -27,7 +27,6 @@
*/
package demo;
-import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -41,69 +40,53 @@ import javax.media.opengl.GLException;
import javax.media.opengl.GLPipelineFactory;
import javax.media.opengl.GLRunnable;
-import com.jogamp.graph.curve.opengl.TextRenderer;
-import com.jogamp.graph.font.Font;
-import com.jogamp.graph.font.FontFactory;
-import com.jogamp.graph.geom.Vertex;
+import com.jogamp.graph.curve.opengl.Renderer;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.KeyListener;
import com.jogamp.newt.opengl.GLWindow;
-import com.jogamp.opengl.util.awt.Screenshot;
/**
*
* Action Keys:
* - 1/2: zoom in/out
- * - 3/4: font +/-
* - 6/7: 2nd pass texture size
* - 0/9: rotate
- * - s: toogle draw 'font set'
- * - f: toggle draw fps
* - v: toggle v-sync
- * - space: toggle font (ubuntu/java)
*/
-public abstract class GPUTextGLListenerBase01 implements GLEventListener {
- Vertex.Factory<? extends Vertex> vfactory;
- protected TextRenderer textRenderer;
- int fontSet = FontFactory.UBUNTU;
- Font font;
- boolean debug;
- boolean trace;
+public abstract class GPURendererListenerBase01 implements GLEventListener {
+ private Screenshot screenshot;
+ private Renderer renderer;
+ private boolean debug;
+ private boolean trace;
- KeyAction keyAction;
+ private KeyAction keyAction;
- volatile GLAutoDrawable autoDrawable = null;
- boolean drawFontSet = true;
- boolean drawFPS = true;
- boolean updateFont = true;
- int fontSize = 40;
- final int fontSizeModulo = 100;
+ private volatile GLAutoDrawable autoDrawable = null;
- final float[] position = new float[] {0,0,0};
+ private final float[] position = new float[] {0,0,0};
- float xTran = -10;
- float yTran = 10;
- float ang = 0f;
- float zoom = -70f;
- int texSize = 400;
+ private float xTran = -10;
+ private float yTran = 10;
+ private float ang = 0f;
+ private float zoom = -70f;
+ private int texSize = 400;
boolean updateMatrix = true;
- static final String text1;
- static final String text2;
- static {
- text1 = "abcdefghijklmnopqrstuvwxyz\nABCDEFGHIJKLMNOPQRSTUVWXYZ\n0123456789.:,;(*!?/\\\")$%^&-+@~#<>{}[]";
- text2 = "The quick brown fox jumps over the lazy dog";
- }
-
- public GPUTextGLListenerBase01(Vertex.Factory<? extends Vertex> vfactory, int mode, boolean debug, boolean trace) {
- // this.font = FontFactory.get(FontFactory.JAVA).getDefault();
- this.font = FontFactory.get(fontSet).getDefault();
- this.vfactory = vfactory;
- this.textRenderer = new TextRenderer(vfactory, mode);
+ public GPURendererListenerBase01(Renderer renderer, boolean debug, boolean trace) {
+ this.renderer = renderer;
this.debug = debug;
this.trace = trace;
+ this.screenshot = new Screenshot();
}
+
+ public final Renderer getRenderer() { return renderer; }
+ public final float getZoom() { return zoom; }
+ public final float getXTran() { return xTran; }
+ public final float getYTran() { return yTran; }
+ public final float getAngle() { return ang; }
+ public final int getTexSize() { return texSize; }
+ public final float[] getPosition() { return position; }
public void setMatrix(float xtrans, float ytrans, float angle, int zoom, int fbosize) {
this.xTran = xtrans;
@@ -130,106 +113,47 @@ public abstract class GPUTextGLListenerBase01 implements GLEventListener {
GL2ES2 gl = drawable.getGL().getGL2ES2();
gl.glViewport(xstart, ystart, width, height);
- textRenderer.reshapePerspective(gl, 45.0f, width, height, 0.1f, 7000.0f);
+ renderer.reshapePerspective(gl, 45.0f, width, height, 0.1f, 7000.0f);
- dumpMatrix(true);
+ dumpMatrix();
}
- protected boolean printScreen = true;
- public void display(GLAutoDrawable drawable) {
- GL2ES2 gl = drawable.getGL().getGL2ES2();
-
- gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Demo02 needs to have this set here as well .. hmm ?
- gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
-
- if(drawFPS || drawFontSet || updateMatrix) {
- final int width = drawable.getWidth();
- final int height = drawable.getHeight();
- final GLAnimatorControl animator = drawable.getAnimator();
- final boolean _drawFPS = drawFPS && null != animator && animator.getTotalFrames()>10;
-
- if(_drawFPS || drawFontSet) {
- textRenderer.reshapeOrtho(null, width, height, 0.1f, 7000.0f);
- }
- if(_drawFPS) {
- final float fps = ( animator.getTotalFrames() * 1000.0f ) / (float) animator.getDuration() ;
- final String fpsS = String.valueOf(fps);
- final int fpsSp = fpsS.indexOf('.');
- textRenderer.resetMatrix(null);
- textRenderer.translate(gl, 0, 0, -6000);
- textRenderer.renderString3D(gl, font, fpsS.substring(0, fpsSp+2), position, fontSize, texSize);
- }
- if(drawFontSet) {
- textRenderer.resetMatrix(null);
- textRenderer.translate(gl, 0, height-50, -6000);
- textRenderer.renderString3D(gl, font, text1, position, fontSize, texSize);
- }
- if(_drawFPS || drawFontSet) {
- textRenderer.reshapePerspective(null, 45.0f, width, height, 0.1f, 7000.0f);
- }
-
- textRenderer.resetMatrix(null);
- textRenderer.translate(null, xTran, yTran, zoom);
- textRenderer.rotate(gl, ang, 0, 1, 0);
- updateMatrix = false;
- }
-
- textRenderer.renderString3D(gl, font, text2, position, fontSize, texSize);
- }
-
+
public void dispose(GLAutoDrawable drawable) {
autoDrawable = null;
GL2ES2 gl = drawable.getGL().getGL2ES2();
- textRenderer.dispose(gl);
+ screenshot.dispose();
+ renderer.dispose(gl);
}
- public void fontIncr(int v) {
- fontSize = Math.abs((fontSize + v) % fontSizeModulo) ;
- updateFont = true;
- dumpMatrix(true);
- }
-
public void zoom(int v){
zoom += v;
updateMatrix = true;
- dumpMatrix(false);
- }
-
- public void nextFontSet() {
- fontSet = ( fontSet == FontFactory.UBUNTU ) ? FontFactory.JAVA : FontFactory.UBUNTU ;
- font = FontFactory.get(fontSet).getDefault();
- }
-
- public void setFontSet(int set, int family, int stylebits) {
- fontSet = set;
- font = FontFactory.get(fontSet).get(family, stylebits);
+ dumpMatrix();
}
public void move(float x, float y){
xTran += x;
yTran += y;
updateMatrix = true;
- dumpMatrix(false);
+ dumpMatrix();
}
public void rotate(float delta){
ang += delta;
ang %= 360.0f;
updateMatrix = true;
- dumpMatrix(false);
+ dumpMatrix();
}
- void dumpMatrix(boolean bbox) {
- System.err.println("Matrix: " + xTran + "/" + yTran + " x"+zoom + " @"+ang +" fontSize "+fontSize);
- if(bbox) {
- System.err.println("bbox: "+font.getStringBounds(text2, fontSize));
- }
+ void dumpMatrix() {
+ System.err.println("Matrix: " + xTran + "/" + yTran + " x"+zoom + " @"+ang);
}
- public void attachTo(GLWindow window) {
+ /** Attach the input listener to the window */
+ public void attachInputListenerTo(GLWindow window) {
if ( null == keyAction ) {
keyAction = new KeyAction();
+ window.addKeyListener(keyAction);
}
- window.addGLEventListener(this);
- window.addKeyListener(keyAction);
}
public void detachFrom(GLWindow window) {
@@ -240,13 +164,13 @@ public abstract class GPUTextGLListenerBase01 implements GLEventListener {
window.removeKeyListener(keyAction);
}
- public void printScreen(String dir, String tech, int width, int height, boolean exportAlpha) throws GLException, IOException {
+ public void printScreen(GLAutoDrawable drawable, String dir, String tech, String objName, boolean exportAlpha) throws GLException, IOException {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
- pw.printf("-%03dx%03d-Z%04d-T%04d-%s", width, height, (int)Math.abs(zoom), texSize, font.getName());
+ pw.printf("-%03dx%03d-Z%04d-T%04d-%s", drawable.getWidth(), drawable.getHeight(), (int)Math.abs(zoom), texSize, objName);
String filename = dir + tech + sw +".tga";
- Screenshot.writeToTargaFile(new File(filename), width, height, exportAlpha);
+ screenshot.surface2File(drawable, filename /*, exportAlpha */);
}
public class KeyAction implements KeyListener {
@@ -257,12 +181,6 @@ public abstract class GPUTextGLListenerBase01 implements GLEventListener {
else if(arg0.getKeyCode() == KeyEvent.VK_2){
zoom(-10);
}
- else if(arg0.getKeyCode() == KeyEvent.VK_3){
- fontIncr(10);
- }
- else if(arg0.getKeyCode() == KeyEvent.VK_4){
- fontIncr(-10);
- }
else if(arg0.getKeyCode() == KeyEvent.VK_UP){
move(0, -1);
}
@@ -289,14 +207,6 @@ public abstract class GPUTextGLListenerBase01 implements GLEventListener {
else if(arg0.getKeyCode() == KeyEvent.VK_9){
rotate(-1);
}
- else if(arg0.getKeyChar() == 's') {
- drawFontSet = !drawFontSet;
- System.err.println("Draw font set: "+drawFontSet);
- }
- else if(arg0.getKeyChar() == 'f'){
- drawFPS = !drawFPS;
- System.err.println("Draw FPS: "+drawFPS);
- }
else if(arg0.getKeyChar() == 'v') {
if(null != autoDrawable) {
autoDrawable.invoke(false, new GLRunnable() {
@@ -314,11 +224,8 @@ public abstract class GPUTextGLListenerBase01 implements GLEventListener {
});
}
}
- else if(arg0.getKeyChar() == ' ') {
- nextFontSet();
- }
}
public void keyTyped(KeyEvent arg0) {}
public void keyReleased(KeyEvent arg0) {}
}
-} \ No newline at end of file
+}
diff --git a/src/demo/GPUTextNewtDemo01.java b/src/demo/GPUTextNewtDemo01.java
index 934eba1ba..9a3067548 100644
--- a/src/demo/GPUTextNewtDemo01.java
+++ b/src/demo/GPUTextNewtDemo01.java
@@ -34,6 +34,7 @@ import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.TextRenderer;
import com.jogamp.graph.geom.opengl.SVertex;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.util.Animator;
@@ -58,14 +59,14 @@ public class GPUTextNewtDemo01 {
caps.setNumSamples(4); // 2 samples is not enough ..
System.out.println("Requested: "+caps);
- window = GLWindow.create(caps);
-
+ window = GLWindow.create(caps);
window.setPosition(10, 10);
window.setSize(800, 400);
-
window.setTitle("GPU Text Newt Demo 01 - r2t0 msaa1");
+
textGLListener = new TextGLListener();
- textGLListener.attachTo(window);
+ textGLListener.attachInputListenerTo(window);
+ window.addGLEventListener(textGLListener);
window.enablePerfLog(true);
window.setVisible(true);
@@ -75,7 +76,7 @@ public class GPUTextNewtDemo01 {
animator.start();
}
- private class TextGLListener extends GPUTextGLListenerBase01 {
+ private class TextGLListener extends GPUTextRendererListenerBase01 {
public TextGLListener() {
super(SVertex.factory(), Region.SINGLE_PASS, DEBUG, TRACE);
// FBO size unrelated with 1 pass
@@ -85,10 +86,12 @@ public class GPUTextNewtDemo01 {
}
public void init(GLAutoDrawable drawable) {
- GL2ES2 gl = drawable.getGL().getGL2ES2();
-
super.init(drawable);
+ GL2ES2 gl = drawable.getGL().getGL2ES2();
+
+ final TextRenderer textRenderer = (TextRenderer) getRenderer();
+
gl.setSwapInterval(1);
gl.glEnable(GL2ES2.GL_DEPTH_TEST);
textRenderer.init(gl);
diff --git a/src/demo/GPUTextNewtDemo02.java b/src/demo/GPUTextNewtDemo02.java
index b46053f1d..2078527dc 100644
--- a/src/demo/GPUTextNewtDemo02.java
+++ b/src/demo/GPUTextNewtDemo02.java
@@ -34,6 +34,7 @@ import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.TextRenderer;
import com.jogamp.graph.geom.opengl.SVertex;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.util.Animator;
@@ -52,8 +53,7 @@ public class GPUTextNewtDemo02 {
public static void main(String[] args) {
GPUTextNewtDemo02 test = new GPUTextNewtDemo02();
- test.testMe();
-
+ test.testMe();
}
GLWindow window;
@@ -61,7 +61,7 @@ public class GPUTextNewtDemo02 {
public void testMe() {
GLProfile.initSingleton(true);
- GLProfile glp = GLProfile.get(GLProfile.GL3bc);
+ GLProfile glp = GLProfile.get(GLProfile.GL3);
GLCapabilities caps = new GLCapabilities(glp);
caps.setAlphaBits(4);
@@ -74,7 +74,8 @@ public class GPUTextNewtDemo02 {
window.setTitle("GPU Text Newt Demo 02 - r2t1 msaa0");
textGLListener = new TextGLListener();
- textGLListener.attachTo(window);
+ textGLListener.attachInputListenerTo(window);
+ window.addGLEventListener(textGLListener);
window.enablePerfLog(true);
window.setVisible(true);
@@ -85,7 +86,7 @@ public class GPUTextNewtDemo02 {
animator.start();
}
- private class TextGLListener extends GPUTextGLListenerBase01 {
+ private class TextGLListener extends GPUTextRendererListenerBase01 {
public TextGLListener() {
super(SVertex.factory(), Region.TWO_PASS, DEBUG, TRACE);
// FIXME: Rami will fix FBO size !!
@@ -95,9 +96,11 @@ public class GPUTextNewtDemo02 {
}
public void init(GLAutoDrawable drawable) {
+ super.init(drawable);
+
GL3 gl = drawable.getGL().getGL3();
- super.init(drawable);
+ final TextRenderer textRenderer = (TextRenderer) getRenderer();
gl.setSwapInterval(1);
gl.glEnable(GL3.GL_DEPTH_TEST);
diff --git a/src/demo/GPUTextRendererListenerBase01.java b/src/demo/GPUTextRendererListenerBase01.java
new file mode 100644
index 000000000..4ee4f62de
--- /dev/null
+++ b/src/demo/GPUTextRendererListenerBase01.java
@@ -0,0 +1,190 @@
+/**
+ * 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 demo;
+
+import java.io.IOException;
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GLAnimatorControl;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLException;
+import com.jogamp.graph.curve.opengl.TextRenderer;
+import com.jogamp.graph.font.Font;
+import com.jogamp.graph.font.FontFactory;
+import com.jogamp.graph.geom.Vertex;
+import com.jogamp.newt.event.KeyEvent;
+import com.jogamp.newt.event.KeyListener;
+import com.jogamp.newt.opengl.GLWindow;
+
+/**
+ *
+ * GPURendererListenerBase01 Keys:
+ * - 1/2: zoom in/out
+ * - 6/7: 2nd pass texture size
+ * - 0/9: rotate
+ * - v: toggle v-sync
+ *
+ * Additional Keys:
+ * - 3/4: font +/-
+ * - s: toogle draw 'font set'
+ * - f: toggle draw fps
+ * - space: toggle font (ubuntu/java)
+ */
+public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerBase01 {
+ int fontSet = FontFactory.UBUNTU;
+ Font font;
+
+ boolean drawFontSet = true;
+ boolean drawFPS = true;
+ boolean updateFont = true;
+ int fontSize = 40;
+ final int fontSizeModulo = 100;
+
+ static final String text1 = "abcdefghijklmnopqrstuvwxyz\nABCDEFGHIJKLMNOPQRSTUVWXYZ\n0123456789.:,;(*!?/\\\")$%^&-+@~#<>{}[]";
+ static final String text2 = "The quick brown fox jumps over the lazy dog";
+
+ public GPUTextRendererListenerBase01(Vertex.Factory<? extends Vertex> factory, int mode, boolean debug, boolean trace) {
+ super(TextRenderer.create(factory, mode), debug, trace);
+ this.font = FontFactory.get(fontSet).getDefault();
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ GL2ES2 gl = drawable.getGL().getGL2ES2();
+
+ gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Demo02 needs to have this set here as well .. hmm ?
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+
+ final TextRenderer textRenderer = (TextRenderer) getRenderer();
+
+ if(drawFPS || drawFontSet || updateMatrix) {
+ final int width = drawable.getWidth();
+ final int height = drawable.getHeight();
+ final GLAnimatorControl animator = drawable.getAnimator();
+ final boolean _drawFPS = drawFPS && null != animator && animator.getTotalFrames()>10;
+
+ if(_drawFPS || drawFontSet) {
+ textRenderer.reshapeOrtho(null, width, height, 0.1f, 7000.0f);
+ }
+ if(_drawFPS) {
+ final float fps = ( animator.getTotalFrames() * 1000.0f ) / (float) animator.getDuration() ;
+ final String fpsS = String.valueOf(fps);
+ final int fpsSp = fpsS.indexOf('.');
+ textRenderer.resetModelview(null);
+ textRenderer.translate(gl, 0, 0, -6000);
+ textRenderer.renderString3D(gl, font, fpsS.substring(0, fpsSp+2), getPosition(), fontSize, getTexSize());
+ }
+ if(drawFontSet) {
+ textRenderer.resetModelview(null);
+ textRenderer.translate(gl, 0, height-50, -6000);
+ textRenderer.renderString3D(gl, font, text1, getPosition(), fontSize, getTexSize());
+ }
+ if(_drawFPS || drawFontSet) {
+ textRenderer.reshapePerspective(null, 45.0f, width, height, 0.1f, 7000.0f);
+ }
+
+ textRenderer.resetModelview(null);
+ textRenderer.translate(null, getXTran(), getYTran(), getZoom());
+ textRenderer.rotate(gl, getAngle(), 0, 1, 0);
+ updateMatrix = false;
+ }
+
+ textRenderer.renderString3D(gl, font, text2, getPosition(), fontSize, getTexSize());
+ }
+
+ public void fontIncr(int v) {
+ fontSize = Math.abs((fontSize + v) % fontSizeModulo) ;
+ updateFont = true;
+ dumpMatrix(true);
+ }
+
+ public void nextFontSet() {
+ fontSet = ( fontSet == FontFactory.UBUNTU ) ? FontFactory.JAVA : FontFactory.UBUNTU ;
+ font = FontFactory.get(fontSet).getDefault();
+ }
+
+ public void setFontSet(int set, int family, int stylebits) {
+ fontSet = set;
+ font = FontFactory.get(fontSet).get(family, stylebits);
+ }
+
+ void dumpMatrix(boolean bbox) {
+ System.err.println("Matrix: " + getXTran() + "/" + getYTran() + " x"+getZoom() + " @"+getAngle() +" fontSize "+fontSize);
+ if(bbox) {
+ System.err.println("bbox: "+font.getStringBounds(text2, fontSize));
+ }
+ }
+
+ KeyAction keyAction = null;
+
+ @Override
+ public void attachInputListenerTo(GLWindow window) {
+ if ( null == keyAction ) {
+ keyAction = new KeyAction();
+ window.addKeyListener(keyAction);
+ super.attachInputListenerTo(window);
+ }
+
+ }
+
+ @Override
+ public void detachFrom(GLWindow window) {
+ super.detachFrom(window);
+ if ( null == keyAction ) {
+ return;
+ }
+ window.removeKeyListener(keyAction);
+ }
+
+ public void printScreen(GLAutoDrawable drawable, String dir, String tech, boolean exportAlpha) throws GLException, IOException {
+ printScreen(drawable, dir, tech, font.getName(), exportAlpha);
+ }
+
+ public class KeyAction implements KeyListener {
+ public void keyPressed(KeyEvent arg0) {
+ if(arg0.getKeyCode() == KeyEvent.VK_3){
+ fontIncr(10);
+ }
+ else if(arg0.getKeyCode() == KeyEvent.VK_4){
+ fontIncr(-10);
+ }
+ else if(arg0.getKeyChar() == 's') {
+ drawFontSet = !drawFontSet;
+ System.err.println("Draw font set: "+drawFontSet);
+ }
+ else if(arg0.getKeyChar() == 'f'){
+ drawFPS = !drawFPS;
+ System.err.println("Draw FPS: "+drawFPS);
+ }
+ else if(arg0.getKeyChar() == ' ') {
+ nextFontSet();
+ }
+ }
+ public void keyTyped(KeyEvent arg0) {}
+ public void keyReleased(KeyEvent arg0) {}
+ }
+} \ No newline at end of file
diff --git a/src/demo/ReadBufferUtil.java b/src/demo/ReadBufferUtil.java
new file mode 100644
index 000000000..1de61974b
--- /dev/null
+++ b/src/demo/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 demo;
+
+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/demo/Screenshot.java b/src/demo/Screenshot.java
new file mode 100644
index 000000000..8e05b17ea
--- /dev/null
+++ b/src/demo/Screenshot.java
@@ -0,0 +1,39 @@
+package demo;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.media.opengl.GL;
+import javax.media.opengl.GLAutoDrawable;
+
+import com.jogamp.opengl.util.texture.TextureIO;
+
+public class Screenshot {
+
+ ReadBufferUtil readBufferUtil = new ReadBufferUtil();
+
+ public void dispose() {
+ readBufferUtil.dispose();
+ }
+
+ public void surface2File(GLAutoDrawable drawable, String filename) {
+ GL gl = drawable.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(filename);
+ } catch (IOException ex) {
+ throw new RuntimeException("can not write survace to file", ex);
+ }
+ }
+
+ void surface2File(String filename) throws IOException {
+ File file = new File(filename);
+ TextureIO.write(readBufferUtil.getTextureData(), file);
+ System.err.println("Wrote: " + file.getAbsolutePath() + ", ...");
+ readBufferUtil.rewindPixelBuffer();
+ }
+
+}