diff options
author | Rami Santina <[email protected]> | 2011-03-29 01:11:44 +0300 |
---|---|---|
committer | Rami Santina <[email protected]> | 2011-03-29 01:11:44 +0300 |
commit | d6aedbf7677e4375d09d0995d3f9c14c5104091b (patch) | |
tree | 8f776e37c8e1bffcf2bf2fd9f73300cd60673b82 /src/demo | |
parent | c0eb49806a35c0618af8a61c99ba783d688fc09d (diff) | |
parent | b73de5a53e2e81e2acc5f8f5064e2b0b27a9804e (diff) |
Merge with changes done for unit tests
Diffstat (limited to 'src/demo')
-rw-r--r-- | src/demo/GPUTextGLListenerBase01.java | 53 | ||||
-rw-r--r-- | src/demo/GPUTextNewtDemo01.java | 5 | ||||
-rw-r--r-- | src/demo/GPUTextNewtDemo02.java | 6 |
3 files changed, 40 insertions, 24 deletions
diff --git a/src/demo/GPUTextGLListenerBase01.java b/src/demo/GPUTextGLListenerBase01.java index 96a06085e..f894f4142 100644 --- a/src/demo/GPUTextGLListenerBase01.java +++ b/src/demo/GPUTextGLListenerBase01.java @@ -27,10 +27,14 @@ */ package demo; +import java.io.File; +import java.io.IOException; + import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLException; import javax.media.opengl.GLPipelineFactory; import com.jogamp.graph.curve.text.HwTextRenderer; @@ -39,16 +43,20 @@ import com.jogamp.graph.geom.Vertex; 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; public abstract class GPUTextGLListenerBase01 implements GLEventListener { Vertex.Factory<? extends Vertex> vfactory; - HwTextRenderer textRenderer; + protected HwTextRenderer textRenderer; + Font font; + boolean debug; + boolean trace; + KeyAction keyAction; boolean updateFont = true; int fontSize = 40; final int fontSizeModulo = 100; - Font font; final float[] position = new float[] {0,0,0}; @@ -56,12 +64,9 @@ public abstract class GPUTextGLListenerBase01 implements GLEventListener { float yTran = 10; float ang = 0f; float zoom = -70f; - // float zoom = -1000f; - int texSize = 400; // FBO/tex size .. + int texSize = 400; boolean updateMatrix = true; - boolean debug; - boolean trace; static final String text1; static final String text2; @@ -71,8 +76,9 @@ public abstract class GPUTextGLListenerBase01 implements GLEventListener { } public GPUTextGLListenerBase01(Vertex.Factory<? extends Vertex> vfactory, int mode, boolean debug, boolean trace) { - this.textRenderer = new HwTextRenderer(vfactory, mode); this.vfactory = vfactory; + this.textRenderer = new HwTextRenderer(vfactory, mode); + this.font = textRenderer.createFont(vfactory, "Lucida Sans Regular"); this.debug = debug; this.trace = trace; } @@ -82,7 +88,8 @@ public abstract class GPUTextGLListenerBase01 implements GLEventListener { this.yTran = ytrans; this.ang = angle; this.zoom = zoom; - this.texSize = fbosize; + this.texSize = fbosize; + updateMatrix = true; } public void init(GLAutoDrawable drawable) { @@ -103,9 +110,9 @@ public abstract class GPUTextGLListenerBase01 implements GLEventListener { gl.glViewport(xstart, ystart, width, height); textRenderer.reshape(gl, 45.0f, width, height, 0.1f, 7000.0f); - dumpMatrix(); + dumpMatrix(true); } - + protected boolean printScreen = true; public void display(GLAutoDrawable drawable) { GL2ES2 gl = drawable.getGL().getGL2ES2(); @@ -119,11 +126,7 @@ public abstract class GPUTextGLListenerBase01 implements GLEventListener { updateMatrix = false; } - if(updateFont) { - font = textRenderer.createFont(vfactory, "Lucida Sans Regular", fontSize); - updateFont = false; - } - textRenderer.renderString3D(gl, font, text2, position, texSize); + textRenderer.renderString3D(gl, font, text2, position, fontSize, texSize); } public void dispose(GLAutoDrawable drawable) { @@ -134,30 +137,33 @@ public abstract class GPUTextGLListenerBase01 implements GLEventListener { public void fontIncr(int v) { fontSize = Math.abs((fontSize + v) % fontSizeModulo) ; updateFont = true; - dumpMatrix(); + dumpMatrix(true); } public void zoom(int v){ zoom += v; updateMatrix = true; - dumpMatrix(); + dumpMatrix(false); } public void move(float x, float y){ xTran += x; yTran += y; updateMatrix = true; - dumpMatrix(); + dumpMatrix(false); } public void rotate(float delta){ ang += delta; ang %= 360.0f; updateMatrix = true; - dumpMatrix(); + dumpMatrix(false); } - void 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)); + } } public void attachTo(GLWindow window) { @@ -176,6 +182,11 @@ public abstract class GPUTextGLListenerBase01 implements GLEventListener { window.removeKeyListener(keyAction); } + public void printScreen(GLWindow window, String dir, String tech, boolean exportAlpha) throws GLException, IOException{ + String filename = dir + tech + "-" + window.getWidth()+ "x" + window.getHeight() + "-" + texSize+ ".tga"; + Screenshot.writeToTargaFile(new File(filename), window.getWidth(), window.getHeight(), exportAlpha); + } + public class KeyAction implements KeyListener { public void keyPressed(KeyEvent arg0) { if(arg0.getKeyCode() == KeyEvent.VK_1){ @@ -215,7 +226,7 @@ public abstract class GPUTextGLListenerBase01 implements GLEventListener { } else if(arg0.getKeyCode() == KeyEvent.VK_9){ rotate(-1); - } + } } public void keyTyped(KeyEvent arg0) {} public void keyReleased(KeyEvent arg0) {} diff --git a/src/demo/GPUTextNewtDemo01.java b/src/demo/GPUTextNewtDemo01.java index ad1020122..362627e56 100644 --- a/src/demo/GPUTextNewtDemo01.java +++ b/src/demo/GPUTextNewtDemo01.java @@ -27,6 +27,7 @@ */ package demo; + import javax.media.opengl.GL2ES2; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; @@ -47,7 +48,7 @@ public class GPUTextNewtDemo01 { } TextGLListener textGLListener = null; - + GLWindow window; public void testMe() { GLProfile.initSingleton(true); GLProfile glp = GLProfile.getGL2ES2(); @@ -57,7 +58,7 @@ public class GPUTextNewtDemo01 { caps.setNumSamples(4); // 2 samples is not enough .. System.out.println("Requested: "+caps); - final GLWindow window = GLWindow.create(caps); + window = GLWindow.create(caps); window.setPosition(10, 10); window.setSize(500, 500); diff --git a/src/demo/GPUTextNewtDemo02.java b/src/demo/GPUTextNewtDemo02.java index c7e7504ab..bda7fe0e2 100644 --- a/src/demo/GPUTextNewtDemo02.java +++ b/src/demo/GPUTextNewtDemo02.java @@ -27,10 +27,13 @@ */ package demo; +import java.io.IOException; + import javax.media.opengl.GL; import javax.media.opengl.GL3; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLException; import javax.media.opengl.GLProfile; import com.jogamp.graph.curve.Region; @@ -53,6 +56,7 @@ public class GPUTextNewtDemo02 { public static void main(String[] args) { GPUTextNewtDemo02 test = new GPUTextNewtDemo02(); test.testMe(); + } GLWindow window; @@ -85,7 +89,7 @@ public class GPUTextNewtDemo02 { private class TextGLListener extends GPUTextGLListenerBase01 { public TextGLListener() { super(SVertex.factory(), Region.TWO_PASS, DEBUG, TRACE); - setMatrix(-10, 10, 0f, -1000, window.getWidth()); + setMatrix(-10, 10, 0f, -1000, 400); } public void init(GLAutoDrawable drawable) { |