aboutsummaryrefslogtreecommitdiffstats
path: root/src/demo/GPUTextGLListenerBase01.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/demo/GPUTextGLListenerBase01.java')
-rw-r--r--src/demo/GPUTextGLListenerBase01.java115
1 files changed, 102 insertions, 13 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) {}