aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/com/jogamp/opengl
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-08-28 06:15:23 +0200
committerSven Gothel <[email protected]>2014-08-28 06:15:23 +0200
commitfc6df2f838388049c6aa6b2cacf9e76dacdb82b2 (patch)
tree243adbce25d0ab16c511df0abd5c7df4d6e6e738 /src/test/com/jogamp/opengl
parent93862d19f0950e4ae5ccadb2613aee173f111b3a (diff)
Graph/Text: Prepare unit tests for font rendering validation (WIP)
Diffstat (limited to 'src/test/com/jogamp/opengl')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/FontSet01.java35
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TestFontsNEWT00.java93
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java99
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWTBugXXXX.java222
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeMono.ttfbin0 -> 592632 bytes
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeMonoBold.ttfbin0 -> 299136 bytes
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeMonoBoldOblique.ttfbin0 -> 298940 bytes
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeMonoOblique.ttfbin0 -> 395188 bytes
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSans.ttfbin0 -> 1563256 bytes
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSansBold.ttfbin0 -> 416128 bytes
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSansBoldOblique.ttfbin0 -> 342492 bytes
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSansOblique.ttfbin0 -> 763676 bytes
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSerif.ttfbin0 -> 3303588 bytes
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSerifBold.ttfbin0 -> 1310828 bytes
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSerifBoldItalic.ttfbin0 -> 608676 bytes
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSerifItalic.ttfbin0 -> 922104 bytes
16 files changed, 425 insertions, 24 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/FontSet01.java b/src/test/com/jogamp/opengl/test/junit/graph/FontSet01.java
new file mode 100644
index 000000000..03a00af78
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/FontSet01.java
@@ -0,0 +1,35 @@
+package com.jogamp.opengl.test.junit.graph;
+
+import java.io.IOException;
+
+import com.jogamp.common.util.IOUtil;
+import com.jogamp.graph.font.Font;
+import com.jogamp.graph.font.FontFactory;
+import com.jogamp.graph.font.FontSet;
+
+public class FontSet01 {
+ public static Font[] getSet01() throws IOException {
+ final Font[] fonts = new Font[11];
+ int i = 0;
+ fonts[i++] = FontFactory.get(FontFactory.UBUNTU).getDefault(); // FontSet.FAMILY_REGULAR, FontSet.STYLE_NONE
+ fonts[i++] = FontFactory.get(FontFactory.UBUNTU).get(FontSet.FAMILY_REGULAR, FontSet.STYLE_ITALIC);
+ fonts[i++] = FontFactory.get(FontFactory.UBUNTU).get(FontSet.FAMILY_REGULAR, FontSet.STYLE_BOLD);
+ fonts[i++] = FontFactory.get(IOUtil.getResource(TestTextRendererNEWTBugXXXX.class,
+ "fonts/freefont/FreeMono.ttf"));
+ fonts[i++] = FontFactory.get(IOUtil.getResource(TestTextRendererNEWTBugXXXX.class,
+ "fonts/freefont/FreeMonoBold.ttf"));
+ fonts[i++] = FontFactory.get(IOUtil.getResource(TestTextRendererNEWTBugXXXX.class,
+ "fonts/freefont/FreeSans.ttf"));
+ fonts[i++] = FontFactory.get(IOUtil.getResource(TestTextRendererNEWTBugXXXX.class,
+ "fonts/freefont/FreeSansBold.ttf"));
+ fonts[i++] = FontFactory.get(IOUtil.getResource(TestTextRendererNEWTBugXXXX.class,
+ "fonts/freefont/FreeSerif.ttf"));
+ fonts[i++] = FontFactory.get(IOUtil.getResource(TestTextRendererNEWTBugXXXX.class,
+ "fonts/freefont/FreeSerifBold.ttf"));
+ fonts[i++] = FontFactory.get(IOUtil.getResource(TestTextRendererNEWTBugXXXX.class,
+ "fonts/freefont/FreeSerifBoldItalic.ttf"));
+ fonts[i++] = FontFactory.get(IOUtil.getResource(TestTextRendererNEWTBugXXXX.class,
+ "fonts/freefont/FreeSerifItalic.ttf"));
+ return fonts;
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestFontsNEWT00.java b/src/test/com/jogamp/opengl/test/junit/graph/TestFontsNEWT00.java
new file mode 100644
index 000000000..e0c6d2ac0
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TestFontsNEWT00.java
@@ -0,0 +1,93 @@
+/**
+ * Copyright 2012 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 com.jogamp.opengl.test.junit.graph;
+
+import java.io.IOException;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.FixMethodOrder;
+import org.junit.runners.MethodSorters;
+
+import com.jogamp.graph.font.Font;
+import com.jogamp.graph.font.Font.Glyph;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestFontsNEWT00 extends UITestCase {
+ static boolean mainRun = false;
+
+ static int atoi(final String a) {
+ try {
+ return Integer.parseInt(a);
+ } catch (final Exception ex) { throw new RuntimeException(ex); }
+ }
+
+ public static void main(final String args[]) throws IOException {
+ mainRun = true;
+ final String tstname = TestFontsNEWT00.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+ @Test
+ public void test00() throws InterruptedException, IOException {
+ testFontImpl(FontSet01.getSet01());
+ }
+ void testFontImpl(final Font[] fonts) throws InterruptedException, IOException {
+ final float fontSize = 10;
+ final float dpi = 96;
+ for(int i=0; i<fonts.length; i++) {
+ final Font font = fonts[i];
+ final float pixelSize = font.getPixelSize(fontSize, dpi);
+ System.err.println(font.getFullFamilyName(null).toString()+": "+fontSize+"p, "+dpi+"dpi -> "+pixelSize+"px:");
+ testFontGlyphAdvancedSize(font, ' ', Glyph.ID_SPACE, fontSize, dpi, pixelSize);
+ testFontGlyphAdvancedSize(font, 'X', 'X', fontSize, dpi, pixelSize);
+ }
+ }
+ void testFontGlyphAdvancedSize(final Font font, final char c, final int glyphID,
+ final float fontSize, final float dpi, final float pixelSize) {
+ final float glyphScale = font.getGlyph(c).getScale(pixelSize);
+ final float fontScale = font.getMetrics().getScale(pixelSize);
+
+ // return this.metrics.getAdvance(pixelSize, useFrationalMetrics);
+ // this.metrics.getAdvance(pixelSize, useFrationalMetrics)
+ // this.advance * this.font.getMetrics().getScale(pixelSize)
+ // font.getHmtxTable().getAdvanceWidth(glyphID) * this.font.getMetrics().getScale(pixelSize)
+ final float spaceAdvanceSizeOfGlyph = font.getGlyph(c).getAdvance(pixelSize, true);
+
+ // font.getHmtxTable().getAdvanceWidth(glyphID) * metrics.getScale(pixelSize);
+ // font.getHmtxTable().getAdvanceWidth(glyphID) * pixelSize * unitsPerEM_Inv;
+ final float spaceAdvanceWidth = font.getAdvanceWidth(glyphID, pixelSize);
+ System.err.println(" Char '"+c+"', "+glyphID+":");
+ System.err.println(" glyphScale "+glyphScale);
+ System.err.println(" glyphSize "+spaceAdvanceSizeOfGlyph);
+ System.err.println(" fontScale "+fontScale);
+ System.err.println(" fontWidth "+spaceAdvanceWidth);
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java
index cb9f3e3d4..9ac5f2668 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java
@@ -27,12 +27,14 @@
*/
package com.jogamp.opengl.test.junit.graph;
+import java.io.File;
import java.io.IOException;
import javax.media.opengl.GL;
import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLDrawable;
+import javax.media.opengl.GLException;
import javax.media.opengl.GLProfile;
import javax.media.opengl.fixedfunc.GLMatrixFunc;
@@ -42,6 +44,8 @@ import org.junit.Test;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
+import com.jogamp.common.util.IOUtil;
+import com.jogamp.graph.curve.Region;
import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.curve.opengl.TextRegionUtil;
@@ -49,8 +53,10 @@ import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontFactory;
import com.jogamp.graph.geom.SVertex;
import com.jogamp.opengl.math.geom.AABBox;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
import com.jogamp.opengl.test.junit.util.NEWTGLContext;
import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.util.GLReadBufferUtil;
import com.jogamp.opengl.util.PMVMatrix;
@@ -64,13 +70,16 @@ public class TestTextRendererNEWT10 extends UITestCase {
static boolean mainRun = false;
static boolean useMSAA = true;
- static final int[] texSize = new int[] { 0 };
- static final int fontSize = 24;
static Font font;
+ static float fontSize = 24;
+ static String customStr = null;
@BeforeClass
public static void setup() throws IOException {
- font = FontFactory.get(FontFactory.UBUNTU).getDefault();
+ if( null == font ) {
+ font = FontFactory.get(FontFactory.UBUNTU).getDefault();
+ // font = FontFactory.get(FontFactory.JAVA).getDefault();
+ }
}
static int atoi(final String a) {
@@ -91,6 +100,15 @@ public class TestTextRendererNEWT10 extends UITestCase {
forceES2 = true;
} else if(args[i].equals("-gl3")) {
forceGL3 = true;
+ } else if(args[i].equals("-font")) {
+ i++;
+ font = FontFactory.get(IOUtil.getResource(TestTextRendererNEWT10.class, args[i]));
+ } else if(args[i].equals("-fontSize")) {
+ i++;
+ fontSize = MiscUtils.atof(args[i], fontSize);
+ } else if(args[i].equals("-text")) {
+ i++;
+ customStr = args[i];
}
}
final String tstname = TestTextRendererNEWT10.class.getName();
@@ -105,16 +123,21 @@ public class TestTextRendererNEWT10 extends UITestCase {
}
// @Test
- public void test00TextRendererNONE01() throws InterruptedException {
- testTextRendererImpl(0);
+ public void test00TextRendererNONE00() throws InterruptedException, GLException, IOException {
+ testTextRendererImpl(0, 0);
+ }
+
+ // @Test
+ public void test01TextRendererMSAA04() throws InterruptedException, GLException, IOException {
+ testTextRendererImpl(0, 4);
}
@Test
- public void testTextRendererMSAA01() throws InterruptedException {
- testTextRendererImpl(4);
+ public void test02TextRendererVBAA04() throws InterruptedException, GLException, IOException {
+ testTextRendererImpl(Region.VBAA_RENDERING_BIT, 4);
}
- void testTextRendererImpl(final int sampleCount) throws InterruptedException {
+ void testTextRendererImpl(final int renderModes, final int sampleCount) throws InterruptedException, GLException, IOException {
final GLProfile glp;
if(forceGL3) {
glp = GLProfile.get(GLProfile.GL3);
@@ -123,13 +146,15 @@ public class TestTextRendererNEWT10 extends UITestCase {
} else {
glp = GLProfile.getGL2ES2();
}
+
final GLCapabilities caps = new GLCapabilities( glp );
caps.setAlphaBits(4);
- if( 0 < sampleCount ) {
+ if( 0 < sampleCount && !Region.isVBAA(renderModes) ) {
caps.setSampleBuffers(true);
caps.setNumSamples(sampleCount);
}
System.err.println("Requested: "+caps);
+ System.err.println("Requested: "+Region.getRenderModeString(renderModes));
final NEWTGLContext.WindowContext winctx = NEWTGLContext.createOnscreenWindow(caps, 800, 400, true);
final GLDrawable drawable = winctx.context.getGLDrawable();
@@ -142,12 +167,13 @@ public class TestTextRendererNEWT10 extends UITestCase {
final RenderState rs = RenderState.createRenderState(SVertex.factory());
final RegionRenderer renderer = RegionRenderer.create(rs, RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
rs.setHintMask(RenderState.BITHINT_GLOBAL_DEPTH_TEST_ENABLED);
- final TextRegionUtil textRenderUtil = new TextRegionUtil(0);
+ final TextRegionUtil textRenderUtil = new TextRegionUtil(renderModes);
// init
gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
renderer.init(gl, 0);
rs.setColorStatic(0.1f, 0.1f, 0.1f, 1.0f);
+ screenshot = new GLReadBufferUtil(false, false);
// reshape
gl.glViewport(0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
@@ -155,32 +181,40 @@ public class TestTextRendererNEWT10 extends UITestCase {
// renderer.reshapePerspective(gl, 45.0f, drawable.getWidth(), drawable.getHeight(), 0.1f, 1000.0f);
renderer.reshapeOrtho(drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), 0.1f, 1000.0f);
+ final int[] sampleCountIO = { sampleCount };
// display
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
- renderString(drawable, gl, renderer, textRenderUtil, "012345678901234567890123456789", 0, 0, -1000);
- renderString(drawable, gl, renderer, textRenderUtil, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, -1, -1000);
- renderString(drawable, gl, renderer, textRenderUtil, "Hello World", 0, -1, -1000);
- renderString(drawable, gl, renderer, textRenderUtil, "4567890123456", 4, -1, -1000);
- renderString(drawable, gl, renderer, textRenderUtil, "I like JogAmp", 4, -1, -1000);
-
- int c = 0;
- renderString(drawable, gl, renderer, textRenderUtil, "GlueGen", c++, -1, -1000);
- renderString(drawable, gl, renderer, textRenderUtil, "JOAL", c++, -1, -1000);
- renderString(drawable, gl, renderer, textRenderUtil, "JOGL", c++, -1, -1000);
- renderString(drawable, gl, renderer, textRenderUtil, "JOCL", c++, -1, -1000);
-
+ if( null == customStr ) {
+ renderString(drawable, gl, renderer, textRenderUtil, "012345678901234567890123456789", 0, 0, -1000, sampleCountIO);
+ renderString(drawable, gl, renderer, textRenderUtil, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, -1, -1000, sampleCountIO);
+ renderString(drawable, gl, renderer, textRenderUtil, "Hello World", 0, -1, -1000, sampleCountIO);
+ renderString(drawable, gl, renderer, textRenderUtil, "4567890123456", 4, -1, -1000,sampleCountIO);
+ renderString(drawable, gl, renderer, textRenderUtil, "I like JogAmp", 4, -1, -1000, sampleCountIO);
+
+ int c = 0;
+ renderString(drawable, gl, renderer, textRenderUtil, "GlueGen", c++, -1, -1000, sampleCountIO);
+ renderString(drawable, gl, renderer, textRenderUtil, "JOAL", c++, -1, -1000, sampleCountIO);
+ renderString(drawable, gl, renderer, textRenderUtil, "JOGL", c++, -1, -1000, sampleCountIO);
+ renderString(drawable, gl, renderer, textRenderUtil, "JOCL", c++, -1, -1000, sampleCountIO);
+ } else {
+ renderString(drawable, gl, renderer, textRenderUtil, customStr, 0, 0, -1000, sampleCountIO);
+ }
drawable.swapBuffers();
+ printScreen(renderModes, drawable, gl, false, sampleCount);
+
sleep();
// dispose
+ screenshot.dispose(gl);
renderer.destroy(gl);
NEWTGLContext.destroyWindow(winctx);
}
+ private GLReadBufferUtil screenshot;
int lastRow = -1;
- void renderString(final GLDrawable drawable, final GL2ES2 gl, final RegionRenderer renderer, final TextRegionUtil textRenderUtil, final String text, final int column, int row, final int z0) {
+ void renderString(final GLDrawable drawable, final GL2ES2 gl, final RegionRenderer renderer, final TextRegionUtil textRenderUtil, final String text, final int column, int row, final int z0, final int[] sampleCount) {
final int height = drawable.getSurfaceHeight();
int dx = 0;
@@ -196,8 +230,25 @@ public class TestTextRendererNEWT10 extends UITestCase {
pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
pmv.glLoadIdentity();
pmv.glTranslatef(dx, dy, z0);
- textRenderUtil.drawString3D(gl, renderer, font, fontSize, text, null, texSize);
+ textRenderUtil.drawString3D(gl, renderer, font, fontSize, text, null, sampleCount);
lastRow = row;
}
+
+ private int screenshot_num = 0;
+
+ public void printScreen(final int renderModes, final GLDrawable drawable, final GL gl, final boolean exportAlpha, final int sampleCount) throws GLException, IOException {
+ final String dir = "./";
+ final String objName = getSimpleTestName(".")+"-snap"+screenshot_num;
+ screenshot_num++;
+ final String modeS = Region.getRenderModeString(renderModes);
+ final String bname = String.format("%s-msaa%02d-fontsz%02.1f-%03dx%03d-%s%04d", objName,
+ drawable.getChosenGLCapabilities().getNumSamples(),
+ TestTextRendererNEWT10.fontSize, drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), modeS, sampleCount);
+ final String filename = dir + bname +".png";
+ if(screenshot.readPixels(gl, false)) {
+ screenshot.write(new File(filename));
+ }
+ }
+
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWTBugXXXX.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWTBugXXXX.java
new file mode 100644
index 000000000..b29d886c9
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWTBugXXXX.java
@@ -0,0 +1,222 @@
+/**
+ * Copyright 2012 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 com.jogamp.opengl.test.junit.graph;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLDrawable;
+import javax.media.opengl.GLException;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.fixedfunc.GLMatrixFunc;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.FixMethodOrder;
+import org.junit.runners.MethodSorters;
+
+import com.jogamp.common.util.IOUtil;
+import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.RenderState;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
+import com.jogamp.graph.curve.opengl.TextRegionUtil;
+import com.jogamp.graph.font.Font;
+import com.jogamp.graph.font.FontFactory;
+import com.jogamp.graph.geom.SVertex;
+import com.jogamp.opengl.math.geom.AABBox;
+import com.jogamp.opengl.test.junit.util.NEWTGLContext;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.util.GLReadBufferUtil;
+import com.jogamp.opengl.util.PMVMatrix;
+
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestTextRendererNEWTBugXXXX extends UITestCase {
+ static long duration = 100; // ms
+ static boolean forceES2 = false;
+ static boolean forceGL3 = false;
+ static boolean mainRun = false;
+ static boolean useMSAA = true;
+ static boolean onlyIssues = false;
+
+ static final float fontSize = 24;
+
+ static int atoi(final String a) {
+ try {
+ return Integer.parseInt(a);
+ } catch (final Exception ex) { throw new RuntimeException(ex); }
+ }
+
+ public static void main(final String args[]) throws IOException {
+ mainRun = true;
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ duration = atoi(args[i]);
+ } else if(args[i].equals("-noMSAA")) {
+ useMSAA = false;
+ } else if(args[i].equals("-es2")) {
+ forceES2 = true;
+ } else if(args[i].equals("-gl3")) {
+ forceGL3 = true;
+ }
+ }
+ final String tstname = TestTextRendererNEWTBugXXXX.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+ static void sleep() {
+ try {
+ System.err.println("** new frame ** (sleep: "+duration+"ms)");
+ Thread.sleep(duration);
+ } catch (final InterruptedException ie) {}
+ }
+
+ @Test
+ public void test00() throws InterruptedException, GLException, IOException {
+ testTextRendererImpl(FontSet01.getSet01(), Region.VBAA_RENDERING_BIT, 4);
+ }
+ void testTextRendererImpl(final Font[] fonts, final int renderModes, final int sampleCount) throws InterruptedException, GLException, IOException {
+ final GLProfile glp;
+ if(forceGL3) {
+ glp = GLProfile.get(GLProfile.GL3);
+ } else if(forceES2) {
+ glp = GLProfile.get(GLProfile.GLES2);
+ } else {
+ glp = GLProfile.getGL2ES2();
+ }
+
+ final GLCapabilities caps = new GLCapabilities( glp );
+ caps.setAlphaBits(4);
+ if( 0 < sampleCount && !Region.isVBAA(renderModes) ) {
+ caps.setSampleBuffers(true);
+ caps.setNumSamples(sampleCount);
+ }
+ System.err.println("Requested: "+caps);
+ System.err.println("Requested: "+Region.getRenderModeString(renderModes));
+
+ final NEWTGLContext.WindowContext winctx =
+ // NEWTGLContext.createOnscreenWindow(caps, 800, 400, true);
+ NEWTGLContext.createOffscreenWindow(caps, 800, 200*fonts.length, true);
+ final GLDrawable drawable = winctx.context.getGLDrawable();
+ final GL2ES2 gl = winctx.context.getGL().getGL2ES2();
+
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+
+ System.err.println("Chosen: "+winctx.window.getChosenCapabilities());
+
+ final RenderState rs = RenderState.createRenderState(SVertex.factory());
+ final RegionRenderer renderer = RegionRenderer.create(rs, RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
+ rs.setHintMask(RenderState.BITHINT_GLOBAL_DEPTH_TEST_ENABLED);
+ final TextRegionUtil textRenderUtil = new TextRegionUtil(renderModes);
+
+ // init
+ gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
+ renderer.init(gl, 0);
+ rs.setColorStatic(0.1f, 0.1f, 0.1f, 1.0f);
+ screenshot = new GLReadBufferUtil(false, false);
+
+ // reshape
+ gl.glViewport(0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
+
+ // renderer.reshapePerspective(gl, 45.0f, drawable.getWidth(), drawable.getHeight(), 0.1f, 1000.0f);
+ renderer.reshapeOrtho(drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), 0.1f, 1000.0f);
+
+ final int[] sampleCountIO = { sampleCount };
+ // display
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+ for(int i=0; i<fonts.length; i++) {
+ final Font font = fonts[i];
+ renderString(drawable, gl, renderer, font, textRenderUtil, font.getFullFamilyName(null).toString()+": "+issues, 0, 0==i?0:-1, -1000, sampleCountIO);
+ if(!onlyIssues) {
+ renderString(drawable, gl, renderer, font, textRenderUtil, "012345678901234567890123456789", 0, -1, -1000, sampleCountIO);
+ renderString(drawable, gl, renderer, font, textRenderUtil, "abcdefghijklmnopqrstuvwxyz", 0, -1, -1000, sampleCountIO);
+ renderString(drawable, gl, renderer, font, textRenderUtil, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 0, -1, -1000, sampleCountIO);
+ renderString(drawable, gl, renderer, font, textRenderUtil, "", 0, -1, -1000, sampleCountIO);
+ renderString(drawable, gl, renderer, font, textRenderUtil, "", 0, -1, -1000, sampleCountIO);
+ }
+ }
+
+ drawable.swapBuffers();
+ printScreen(renderModes, drawable, gl, false, sampleCount);
+
+ sleep();
+
+ // dispose
+ screenshot.dispose(gl);
+ renderer.destroy(gl);
+
+ NEWTGLContext.destroyWindow(winctx);
+ }
+
+ private static final String issues = "m M n u 8 g q Q";
+ private GLReadBufferUtil screenshot;
+ int lastRow = -1;
+
+ void renderString(final GLDrawable drawable, final GL2ES2 gl, final RegionRenderer renderer, final Font font, final TextRegionUtil textRenderUtil, final String text, final int column, int row, final int z0, final int[] sampleCount) {
+ final int height = drawable.getSurfaceHeight();
+
+ int dx = 0;
+ int dy = height;
+ if(0>row) {
+ row = lastRow + 1;
+ }
+ final AABBox textBox = font.getMetricBounds(text, fontSize);
+ dx += font.getAdvanceWidth('X', fontSize) * column;
+ dy -= (int)textBox.getHeight() * ( row + 1 );
+
+ final PMVMatrix pmv = renderer.getMatrix();
+ pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
+ pmv.glLoadIdentity();
+ pmv.glTranslatef(dx, dy, z0);
+ textRenderUtil.drawString3D(gl, renderer, font, fontSize, text, null, sampleCount);
+
+ lastRow = row;
+ }
+
+ private int screenshot_num = 0;
+
+ public void printScreen(final int renderModes, final GLDrawable drawable, final GL gl, final boolean exportAlpha, final int sampleCount) throws GLException, IOException {
+ final String dir = "./";
+ final String objName = getSimpleTestName(".")+"-snap"+screenshot_num;
+ screenshot_num++;
+ final String modeS = Region.getRenderModeString(renderModes);
+ final String bname = String.format("%s-msaa%02d-fontsz%02.1f-%03dx%03d-%s%04d", objName,
+ drawable.getChosenGLCapabilities().getNumSamples(),
+ TestTextRendererNEWTBugXXXX.fontSize, drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), modeS, sampleCount);
+ final String filename = dir + bname +".png";
+ if(screenshot.readPixels(gl, false)) {
+ screenshot.write(new File(filename));
+ }
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeMono.ttf b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeMono.ttf
new file mode 100644
index 000000000..c4200565a
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeMono.ttf
Binary files differ
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeMonoBold.ttf b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeMonoBold.ttf
new file mode 100644
index 000000000..0bee057ec
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeMonoBold.ttf
Binary files differ
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeMonoBoldOblique.ttf b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeMonoBoldOblique.ttf
new file mode 100644
index 000000000..91bbc0e8a
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeMonoBoldOblique.ttf
Binary files differ
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeMonoOblique.ttf b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeMonoOblique.ttf
new file mode 100644
index 000000000..3252bdda6
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeMonoOblique.ttf
Binary files differ
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSans.ttf b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSans.ttf
new file mode 100644
index 000000000..e56dc6e90
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSans.ttf
Binary files differ
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSansBold.ttf b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSansBold.ttf
new file mode 100644
index 000000000..66e19ecb0
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSansBold.ttf
Binary files differ
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSansBoldOblique.ttf b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSansBoldOblique.ttf
new file mode 100644
index 000000000..de8a9e153
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSansBoldOblique.ttf
Binary files differ
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSansOblique.ttf b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSansOblique.ttf
new file mode 100644
index 000000000..b0357eabb
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSansOblique.ttf
Binary files differ
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSerif.ttf b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSerif.ttf
new file mode 100644
index 000000000..dffa1aedb
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSerif.ttf
Binary files differ
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSerifBold.ttf b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSerifBold.ttf
new file mode 100644
index 000000000..e2393ad22
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSerifBold.ttf
Binary files differ
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSerifBoldItalic.ttf b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSerifBoldItalic.ttf
new file mode 100644
index 000000000..46bc4695f
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSerifBoldItalic.ttf
Binary files differ
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSerifItalic.ttf b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSerifItalic.ttf
new file mode 100644
index 000000000..d173e3566
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/fonts/freefont/FreeSerifItalic.ttf
Binary files differ