diff options
Diffstat (limited to 'src/demo')
-rw-r--r-- | src/demo/GPUTextGLListenerBase01.java | 115 | ||||
-rw-r--r-- | src/demo/GPUTextNewtDemo01.java | 12 | ||||
-rw-r--r-- | src/demo/GPUTextNewtDemo02.java | 13 |
3 files changed, 119 insertions, 21 deletions
diff --git a/src/demo/GPUTextGLListenerBase01.java b/src/demo/GPUTextGLListenerBase01.java index 4e3a57fd9..eee1efbdb 100644 --- a/src/demo/GPUTextGLListenerBase01.java +++ b/src/demo/GPUTextGLListenerBase01.java @@ -29,31 +29,52 @@ package demo; import java.io.File; import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; +import javax.media.opengl.GLAnimatorControl; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLEventListener; import javax.media.opengl.GLException; import javax.media.opengl.GLPipelineFactory; +import javax.media.opengl.GLRunnable; import com.jogamp.graph.curve.HwTextRenderer; 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; 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 HwTextRenderer textRenderer; + protected HwTextRenderer textRenderer; + int fontSet = FontFactory.UBUNTU; Font font; boolean debug; boolean trace; KeyAction keyAction; + volatile GLAutoDrawable autoDrawable = null; + boolean drawFontSet = true; + boolean drawFPS = true; boolean updateFont = true; int fontSize = 40; final int fontSizeModulo = 100; @@ -71,15 +92,15 @@ public abstract class GPUTextGLListenerBase01 implements GLEventListener { static final String text2; static { - //text1 = "abcdef\nghijklmn\nopqrstuv\nwxyz\n0123456789"; - text1 = "abcdef\nghijklmn\nopqrstuv\nwxyz\n#$!%-+="; - text2 = text1.toUpperCase(); + 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 HwTextRenderer(vfactory, mode); - this.font = textRenderer.createFont(vfactory, "Lucida Sans Regular"); this.debug = debug; this.trace = trace; } @@ -94,8 +115,8 @@ public abstract class GPUTextGLListenerBase01 implements GLEventListener { } public void init(GLAutoDrawable drawable) { + autoDrawable = drawable; GL2ES2 gl = drawable.getGL().getGL2ES2(); - if(debug) { gl = gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", null, gl, null) ).getGL2ES2(); } @@ -109,7 +130,7 @@ public abstract class GPUTextGLListenerBase01 implements GLEventListener { GL2ES2 gl = drawable.getGL().getGL2ES2(); gl.glViewport(xstart, ystart, width, height); - textRenderer.reshape(gl, 45.0f, width, height, 0.1f, 7000.0f); + textRenderer.reshapePerspective(gl, 45.0f, width, height, 0.1f, 7000.0f); dumpMatrix(true); } @@ -120,9 +141,34 @@ public abstract class GPUTextGLListenerBase01 implements GLEventListener { 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(updateMatrix) { - textRenderer.resetMatrix(gl); - textRenderer.translate(gl, xTran, yTran, zoom); + 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; } @@ -131,6 +177,7 @@ public abstract class GPUTextGLListenerBase01 implements GLEventListener { } public void dispose(GLAutoDrawable drawable) { + autoDrawable = null; GL2ES2 gl = drawable.getGL().getGL2ES2(); textRenderer.dispose(gl); } @@ -147,6 +194,16 @@ public abstract class GPUTextGLListenerBase01 implements GLEventListener { 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); + } + public void move(float x, float y){ xTran += x; yTran += y; @@ -183,9 +240,13 @@ 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() + "-T" + texSize + "-Z" + Math.abs(zoom) +".tga"; - Screenshot.writeToTargaFile(new File(filename), window.getWidth(), window.getHeight(), exportAlpha); + public void printScreen(String dir, String tech, int width, int height, 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()); + + String filename = dir + tech + sw +".tga"; + Screenshot.writeToTargaFile(new File(filename), width, height, exportAlpha); } public class KeyAction implements KeyListener { @@ -228,6 +289,34 @@ 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() { + public void run(GLAutoDrawable drawable) { + GL gl = drawable.getGL(); + int i = gl.getSwapInterval(); + i = i==0 ? 1 : 0; + gl.setSwapInterval(i); + final GLAnimatorControl a = drawable.getAnimator(); + if( null != a ) { + a.resetCounter(); + } + System.err.println("Swap Interval: "+i); + } + }); + } + } + else if(arg0.getKeyChar() == ' ') { + nextFontSet(); + } } public void keyTyped(KeyEvent arg0) {} public void keyReleased(KeyEvent arg0) {} diff --git a/src/demo/GPUTextNewtDemo01.java b/src/demo/GPUTextNewtDemo01.java index a07ead417..934eba1ba 100644 --- a/src/demo/GPUTextNewtDemo01.java +++ b/src/demo/GPUTextNewtDemo01.java @@ -36,7 +36,7 @@ import javax.media.opengl.GLProfile; import com.jogamp.graph.curve.Region; import com.jogamp.graph.geom.opengl.SVertex; import com.jogamp.newt.opengl.GLWindow; -import com.jogamp.opengl.util.FPSAnimator; +import com.jogamp.opengl.util.Animator; public class GPUTextNewtDemo01 { static final boolean DEBUG = false; @@ -61,14 +61,16 @@ public class GPUTextNewtDemo01 { window = GLWindow.create(caps); window.setPosition(10, 10); - window.setSize(400, 400); + window.setSize(800, 400); window.setTitle("GPU Text Newt Demo 01 - r2t0 msaa1"); textGLListener = new TextGLListener(); textGLListener.attachTo(window); + window.enablePerfLog(true); window.setVisible(true); - FPSAnimator animator = new FPSAnimator(10); + // FPSAnimator animator = new FPSAnimator(10); + Animator animator = new Animator(); animator.add(window); animator.start(); } @@ -76,8 +78,10 @@ public class GPUTextNewtDemo01 { private class TextGLListener extends GPUTextGLListenerBase01 { public TextGLListener() { super(SVertex.factory(), Region.SINGLE_PASS, DEBUG, TRACE); + // FBO size unrelated with 1 pass //setMatrix(-10, 10, 0f, -70, 0); - setMatrix(-10, 10, 0f, -100, 400); + // setMatrix(-80, -30, 0f, -100, 0); + setMatrix(-400, -30, 0f, -500, 0); } public void init(GLAutoDrawable drawable) { diff --git a/src/demo/GPUTextNewtDemo02.java b/src/demo/GPUTextNewtDemo02.java index 012ee9936..b46053f1d 100644 --- a/src/demo/GPUTextNewtDemo02.java +++ b/src/demo/GPUTextNewtDemo02.java @@ -36,7 +36,7 @@ import javax.media.opengl.GLProfile; import com.jogamp.graph.curve.Region; import com.jogamp.graph.geom.opengl.SVertex; import com.jogamp.newt.opengl.GLWindow; -import com.jogamp.opengl.util.FPSAnimator; +import com.jogamp.opengl.util.Animator; public class GPUTextNewtDemo02 { /** @@ -70,15 +70,17 @@ public class GPUTextNewtDemo02 { window = GLWindow.create(caps); window.setPosition(10, 10); - window.setSize(400, 400); + window.setSize(800, 400); window.setTitle("GPU Text Newt Demo 02 - r2t1 msaa0"); textGLListener = new TextGLListener(); textGLListener.attachTo(window); + window.enablePerfLog(true); window.setVisible(true); - FPSAnimator animator = new FPSAnimator(60); + // FPSAnimator animator = new FPSAnimator(60); + Animator animator = new Animator(); animator.add(window); animator.start(); } @@ -86,7 +88,10 @@ public class GPUTextNewtDemo02 { private class TextGLListener extends GPUTextGLListenerBase01 { public TextGLListener() { super(SVertex.factory(), Region.TWO_PASS, DEBUG, TRACE); - setMatrix(-10, 10, 0f, -100, 400); + // FIXME: Rami will fix FBO size !! + // setMatrix(-10, 10, 0f, -100, 400); + // setMatrix(-80, -30, 0f, -100, window.getWidth()*3); + setMatrix(-400, -30, 0f, -500, window.getWidth()*3); } public void init(GLAutoDrawable drawable) { |