aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/com/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-02-17 22:40:16 +0100
committerSven Gothel <[email protected]>2023-02-17 22:40:16 +0100
commit0f86f8fc54855b6453e5c270b3480632f3a401d1 (patch)
treee7550854ceaa7fc05f051b2b37efd75e23f4627d /src/test/com/jogamp
parent3573631ced62383b9871f98f65f354958042331b (diff)
Graph Overflow Bug: Reorder TestTextRendererNEWT* tests from simple to complex example code, ascending
Diffstat (limited to 'src/test/com/jogamp')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java2
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java436
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java362
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java479
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT20.java316
5 files changed, 805 insertions, 790 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java b/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java
index b9d62cac4..b7aff2f79 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2010 JogAmp Community. All rights reserved.
+ * Copyright 2011-2023 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:
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java
deleted file mode 100644
index 5db5c09ea..000000000
--- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java
+++ /dev/null
@@ -1,436 +0,0 @@
-/**
- * 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 java.net.URL;
-import java.util.Locale;
-
-import com.jogamp.opengl.GL;
-import com.jogamp.opengl.GL2ES2;
-import com.jogamp.opengl.GLAnimatorControl;
-import com.jogamp.opengl.GLAutoDrawable;
-import com.jogamp.opengl.GLCapabilities;
-import com.jogamp.opengl.GLCapabilitiesImmutable;
-import com.jogamp.opengl.GLException;
-import com.jogamp.opengl.GLProfile;
-import com.jogamp.opengl.GLRunnable;
-
-import org.junit.Assert;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-
-import com.jogamp.common.os.Platform;
-import com.jogamp.graph.curve.Region;
-import com.jogamp.graph.curve.opengl.GLRegion;
-import com.jogamp.graph.curve.opengl.RegionRenderer;
-import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.font.Font;
-import com.jogamp.graph.font.FontFactory;
-import com.jogamp.graph.font.FontScale;
-import com.jogamp.graph.geom.SVertex;
-import com.jogamp.junit.util.JunitTracer;
-import com.jogamp.newt.Window;
-import com.jogamp.newt.opengl.GLWindow;
-import com.jogamp.opengl.test.junit.util.MiscUtils;
-import com.jogamp.opengl.test.junit.util.UITestCase;
-import com.jogamp.opengl.util.Animator;
-import com.jogamp.opengl.util.GLReadBufferUtil;
-
-
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class TestTextRendererNEWT00 extends UITestCase {
- static final boolean DEBUG = false;
- static final boolean TRACE = false;
- static long Duration = 2000; // ms
- static int win_width = 1024;
- static int win_height = 640;
- static boolean WaitStartEnd = false;
- static boolean TextAnim = false;
- static int SceneMSAASamples = 0;
- static int GraphVBAASamples = 0;
- static int GraphMSAASamples = 0;
- static boolean ManualTest = false;
- static int SwapInterval = 1;
-
- static String fontFileName = null;
- static URL fontURL = null;
- static int fontSet = 0;
- static int fontFamily = 0;
- static int fontStylebits = 0;
- static float fontSizeFixed = 14f;
-
- 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 {
- ManualTest = args.length > 0;
- for(int i=0; i<args.length; i++) {
- if(args[i].equals("-time")) {
- i++;
- Duration = atoi(args[i]);
- } else if(args[i].equals("-width")) {
- i++;
- win_width = atoi(args[i]);
- } else if(args[i].equals("-height")) {
- i++;
- win_height = atoi(args[i]);
- } else if(args[i].equals("-fontURL")) {
- i++;
- fontURL = new URL(args[i]);
- } else if(args[i].equals("-fontFile")) {
- i++;
- fontFileName = args[i];
- } else if(args[i].equals("-fontSet")) {
- i++;
- fontSet = atoi(args[i]);
- } else if(args[i].equals("-fontFamily")) {
- i++;
- fontFamily = atoi(args[i]);
- } else if(args[i].equals("-fontStyle")) {
- i++;
- fontStylebits = atoi(args[i]);
- } else if(args[i].equals("-fontSize")) {
- i++;
- fontSizeFixed = atoi(args[i]);
- } else if(args[i].equals("-smsaa")) {
- i++;
- SceneMSAASamples = atoi(args[i]);
- } else if(args[i].equals("-gmsaa")) {
- i++;
- GraphMSAASamples = atoi(args[i]);
- } else if(args[i].equals("-gvbaa")) {
- i++;
- GraphVBAASamples = atoi(args[i]);
- } else if(args[i].equals("-textAnim")) {
- TextAnim = true;
- } else if(args[i].equals("-vsync")) {
- i++;
- SwapInterval = MiscUtils.atoi(args[i], SwapInterval);
- } else if(args[i].equals("-wait")) {
- WaitStartEnd = true;
- }
- }
- System.err.println("Font [set "+fontSet+", family "+fontFamily+", style "+fontStylebits+", size "+fontSizeFixed+"], fontFileName "+fontFileName);
- System.err.println("Scene MSAA Samples "+SceneMSAASamples);
- System.err.println("Graph MSAA Samples "+GraphMSAASamples);
- System.err.println("Graph VBAA Samples "+GraphVBAASamples);
- System.err.println("swapInterval "+SwapInterval);
- final String tstname = TestTextRendererNEWT00.class.getName();
- org.junit.runner.JUnitCore.main(tstname);
- }
-
- static void sleep() {
- sleep(Duration);
- }
- static void sleep(final long d) {
- try {
- System.err.println("** new frame ** (sleep: "+d+"ms)");
- Thread.sleep(d);
- } catch (final InterruptedException ie) {}
- }
-
- static void destroyWindow(final GLWindow window) {
- if(null!=window) {
- window.destroy();
- }
- }
-
- static GLWindow createWindow(final String title, final GLCapabilitiesImmutable caps, final int width, final int height) {
- Assert.assertNotNull(caps);
-
- final GLWindow window = GLWindow.create(caps);
- window.setSize(width, height);
- window.setPosition(10, 10);
- window.setTitle(title);
- Assert.assertNotNull(window);
- window.setVisible(true);
-
- return window;
- }
-
- @Test
- public void test00Manual() throws InterruptedException {
- if( ManualTest ) {
- testImpl(SceneMSAASamples, GraphMSAASamples, GraphVBAASamples);
- }
- }
- @Test
- public void test00SceneNoAA() throws InterruptedException {
- if( !ManualTest ) {
- testImpl(0, 0, 0);
- }
- }
- @Test
- public void test01SceneMSAA04() throws InterruptedException {
- if( !ManualTest ) {
- testImpl(4, 0, 0);
- }
- }
- @Test
- public void test02GraphMSAA04() throws InterruptedException {
- if( !ManualTest ) {
- testImpl(0, 4, 0);
- }
- }
- @Test
- public void test03GraphVBAA04() throws InterruptedException {
- if( !ManualTest ) {
- testImpl(0, 0, 4);
- }
- }
-
- public void testImpl(final int sceneMSAASamples, final int graphMSAASamples, final int graphVBAASamples) throws InterruptedException {
- final GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
- final GLCapabilities caps = new GLCapabilities(glp);
- caps.setAlphaBits(4);
- if( 0 < sceneMSAASamples ) {
- caps.setSampleBuffers(true);
- caps.setNumSamples(sceneMSAASamples);
- }
- System.err.println("Requested: "+caps+", graph[msaaSamples "+graphMSAASamples+", vbaaSamples "+graphVBAASamples+"]");
-
- final GLWindow window = createWindow("text-gvbaa"+graphVBAASamples+"-gmsaa"+graphMSAASamples+"-smsaa"+sceneMSAASamples, caps, win_width, win_height);
-
- window.display();
- System.err.println("Chosen: "+window.getChosenGLCapabilities());
- if( WaitStartEnd ) {
- JunitTracer.waitForKey("Start");
- }
-
- final RenderState rs = RenderState.createRenderState(SVertex.factory());
- final int renderModes, sampleCount;
- if( graphVBAASamples > 0 ) {
- renderModes = Region.VBAA_RENDERING_BIT;
- sampleCount = graphVBAASamples;
- } else if ( graphMSAASamples > 0 ) {
- renderModes = Region.MSAA_RENDERING_BIT;
- sampleCount = graphMSAASamples;
- } else {
- renderModes = 0;
- sampleCount = 0;
- }
- final TextRendererGLEL textGLListener = new TextRendererGLEL(rs, renderModes, sampleCount);
- System.err.println(textGLListener.getFontInfo());
-
- window.addGLEventListener(textGLListener);
-
- final Animator anim = new Animator();
- anim.add(window);
- anim.start();
- anim.setUpdateFPSFrames(60, null);
- sleep();
- window.invoke(true, new GLRunnable() {
- @Override
- public boolean run(final GLAutoDrawable drawable) {
- try {
- textGLListener.printScreen(renderModes, drawable, "./", "TestTextRendererNEWT00-snap"+screenshot_num, false);
- screenshot_num++;
- } catch (final Exception e) {
- e.printStackTrace();
- }
- return true;
- }
- });
- anim.stop();
- if( WaitStartEnd ) {
- JunitTracer.waitForKey("Stop");
- }
- destroyWindow(window);
- }
- int screenshot_num = 0;
-
- static final String textX2 =
- "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec sapien tellus. \n"+
- "Ut purus odio, rhoncus sit amet commodo eget, ullamcorper vel urna. Mauris ultricies \n"+
- "quam iaculis urna cursus ornare. Nullam ut felis a ante ultrices ultricies nec a elit. \n"+
- "In hac habitasse platea dictumst. Vivamus et mi a quam lacinia pharetra at venenatis est.\n"+
- "Morbi quis bibendum nibh. Donec lectus orci, sagittis in consequat nec, volutpat nec nisi.\n"+
- "Donec ut dolor et nulla tristique varius. In nulla magna, fermentum id tempus quis, semper \n"+
- "in lorem. Maecenas in ipsum ac justo scelerisque sollicitudin. Quisque sit amet neque lorem,\n" +
- "-------Press H to change text---------\n";
-
- private static final class TextRendererGLEL extends TextRendererGLELBase {
- private final GLReadBufferUtil screenshot;
- private final GLRegion regionFPS, regionFPSAnim;
- final Font font;
- final float fontSizeMin, fontSizeMax;
- private long t0;
- float fontSizeAnim, fontSizeDelta;
- float dpiV, ppmmV;
-
- TextRendererGLEL(final RenderState rs, final int renderModes, final int sampleCount) {
- super(renderModes, new int[] { sampleCount });
- setRendererCallbacks(RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
- setRenderState(rs);
-
- regionFPS = GLRegion.create(renderModes, null);
- regionFPSAnim = GLRegion.create(renderModes, null);
- if( null != fontURL ) {
- Font _font = null;
- try {
- _font = FontFactory.get(fontURL.openStream(), true);
- } catch (final IOException e) {
- e.printStackTrace();
- }
- font = _font;
- } else if( null != fontFileName ) {
- Font _font = null;
- try {
- _font = FontFactory.get(getClass(), fontFileName, false);
- } catch (final IOException e) {
- e.printStackTrace();
- }
- font = _font;
- } else {
- font = getFont(fontSet, fontFamily, fontStylebits);
- }
-
- staticRGBAColor[0] = 0.1f;
- staticRGBAColor[1] = 0.1f;
- staticRGBAColor[2] = 0.1f;
- staticRGBAColor[3] = 1.0f;
-
- this.screenshot = new GLReadBufferUtil(false, false);
- // fontSizeMin = Math.max(8, fontSizeFixed-5);
- fontSizeMin = fontSizeFixed;
- fontSizeMax = fontSizeFixed+8;
- fontSizeAnim = fontSizeFixed;
- fontSizeDelta = 0.01f;
- }
-
- @Override
- public void init(final GLAutoDrawable drawable) {
- super.init(drawable);
- final GL2ES2 gl = drawable.getGL().getGL2ES2();
- gl.setSwapInterval(SwapInterval);
- gl.glEnable(GL.GL_DEPTH_TEST);
- t0 = Platform.currentTimeMillis();
-
- final Window win = (Window)drawable.getUpstreamWidget();
- final float[] pixelsPerMM = win.getPixelsPerMM(new float[2]);
- final float[] dotsPerInch = FontScale.ppmmToPPI(pixelsPerMM, new float[2]);
- dpiV = dotsPerInch[1];
- ppmmV = pixelsPerMM[1];
- System.err.println(getFontInfo());
- System.err.println("fontSize "+fontSizeFixed+", dotsPerMM "+pixelsPerMM[0]+"x"+pixelsPerMM[1]+", dpi "+dotsPerInch[0]+"x"+dotsPerInch[1]+", pixelSize "+FontScale.toPixels(fontSizeFixed, dotsPerInch[1] /* dpi display */));
- }
-
- @Override
- public void dispose(final GLAutoDrawable drawable) {
- final GL2ES2 gl = drawable.getGL().getGL2ES2();
- screenshot.dispose(gl);
- regionFPS.destroy(gl);
- regionFPSAnim.destroy(gl);
- super.dispose(drawable);
- }
-
- public void printScreen(final int renderModes, final GLAutoDrawable drawable, final String dir, final String objName, final boolean exportAlpha) throws GLException, IOException {
- final String modeS = Region.getRenderModeString(renderModes);
- final String bname = String.format((Locale)null, "%s-msaa%02d-fontsz%02.1f-%03dx%03d-%s%04d", objName,
- drawable.getChosenGLCapabilities().getNumSamples(),
- fontSizeFixed, drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), modeS, vbaaSampleCount[0]);
- final String filename = dir + bname +".png";
- if(screenshot.readPixels(drawable.getGL(), false)) {
- screenshot.write(new File(filename));
- }
- }
-
- String getFontInfo() {
- final float pixelSize = FontScale.toPixels(fontSizeFixed, dpiV);
- final float mmSize = pixelSize / ppmmV;
- final int unitsPerEM = font.getMetrics().getUnitsPerEM();
- return String.format("Resolution dpiV %.2f, %.2f px/mm%nFont %s, unitsPerEM %d, size %.2f pt %.2f px %2f mm%n",
- dpiV, ppmmV,
- font.getFullFamilyName(),unitsPerEM, fontSizeFixed, pixelSize, mmSize);
- }
-
- @Override
- public void display(final GLAutoDrawable drawable) {
- final 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);
-
- final GLAnimatorControl anim = drawable.getAnimator();
- final float lfps = null != anim ? anim.getLastFPS() : 0f;
- final float tfps = null != anim ? anim.getTotalFPS() : 0f;
-
- // Note: MODELVIEW is from [ 0 .. height ]
-
- final long t1 = Platform.currentTimeMillis();
-
- // final float fontSize = TestTextRendererNEWT00.fontSize;
-
- fontSizeAnim += fontSizeDelta;
- if( fontSizeMin >= fontSizeAnim || fontSizeAnim >= fontSizeMax ) {
- fontSizeDelta *= -1f;
- }
-
- final float pixelSize = FontScale.toPixels(fontSizeFixed, dpiV);
- final float pixelSizeAnim = FontScale.toPixels(fontSizeAnim, dpiV);
-
- final String modeS = Region.getRenderModeString(renderModes);
-
- if( false ) {
- // renderString(drawable, font, pixelSize, "I - / H P 7 0", 0, 0, 0, 0, -1000f, true);
- // renderString(drawable, font, pixelSize, "A M > } ] ", 0, 0, 0, 0, -1000f, true);
- // renderString(drawable, font, pixelSize, "M", 0, 0, 0, 0, -1000f, true);
- // renderString(drawable, font, pixelSize, "0 6 9 a b O Q A M > } ] ", 0, 0, 0, 0, -1000f, true);
- // renderString(drawable, font, pixelSize, "012345678901234567890123456789", 0, 0, 0, -1000, true);
- // renderString(drawable, font, pixelSize, textX2, 0, 0, 0, 0, -1000f, true);
- // renderString(drawable, font, pixelSize, text1, 0, 0, 0, -1000f, regionFPS); // no-cache
- final String text1 = lfps+" / "+tfps+" fps, vsync "+gl.getSwapInterval()+", elapsed "+(t1-t0)/1000.0+
- " s, fontSize "+fontSizeFixed+", msaa "+drawable.getChosenGLCapabilities().getNumSamples()+
- ", "+modeS+"-samples "+vbaaSampleCount[0];
- renderString(drawable, font, pixelSize, text1, 0, 0, 0, 0, -1000, regionFPS); // no-cache
- } else {
- final String text1 = String.format("%03.1f/%03.1f fps, vsync %d, elapsed %4.1f s, fontSize %2.2f, msaa %d, %s-samples %d",
- lfps, tfps, gl.getSwapInterval(), (t1-t0)/1000.0, fontSizeFixed,
- drawable.getChosenGLCapabilities().getNumSamples(), modeS, vbaaSampleCount[0]);
- renderString(drawable, font, pixelSize, getFontInfo(), 0, 0, 0, 0, -1000, true);
- renderString(drawable, font, pixelSize, "012345678901234567890123456789", 0, 0, 0, -1000, true);
- renderString(drawable, font, pixelSize, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, 0, 0, -1000, true);
- renderString(drawable, font, pixelSize, "Hello World", 0, 0, 0, -1000, true);
- renderString(drawable, font, pixelSize, "4567890123456", 4, 0, 0, -1000, true);
- renderString(drawable, font, pixelSize, "I like JogAmp", 4, 0, 0, -1000, true);
- renderString(drawable, font, pixelSize, "Hello World", 0, 0, 0, -1000, true);
- renderString(drawable, font, pixelSize, textX2, 0, 0, 0, -1000, true);
- renderString(drawable, font, pixelSize, text1, 0, 0, 0, -1000, regionFPS); // no-cache
- if( TextAnim ) {
- renderString(drawable, font, pixelSizeAnim, text1, 0, 0, 0, -1000, regionFPSAnim); // no-cache
- }
- }
- } };
-
-}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java
index ec539d6db..eb6a61bec 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2010 JogAmp Community. All rights reserved.
+ * Copyright 2011-2023 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:
@@ -27,43 +27,70 @@
*/
package com.jogamp.opengl.test.junit.graph;
+import java.io.File;
import java.io.IOException;
+import java.util.Locale;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2ES2;
-import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
-import com.jogamp.opengl.GLCapabilitiesImmutable;
+import com.jogamp.opengl.GLDrawable;
import com.jogamp.opengl.GLException;
import com.jogamp.opengl.GLProfile;
-import com.jogamp.opengl.math.geom.AABBox;
-
-import jogamp.common.os.PlatformPropsImpl;
+import com.jogamp.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.os.Platform;
+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.font.FontScale;
import com.jogamp.graph.geom.SVertex;
-import com.jogamp.newt.opengl.GLWindow;
-import com.jogamp.opengl.test.junit.graph.demos.GPUTextRendererListenerBase01;
+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;
+/**
+ * TestTextRendererNEWT01 Variant
+ * - No listener, all straight forward
+ * - Type Rendering via TextRegionUtil, multiple
+ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestTextRendererNEWT01 extends UITestCase {
static final boolean DEBUG = false;
static final boolean TRACE = false;
static long duration = 100; // ms
+ static boolean forceES2 = false;
+ static boolean forceGL3 = false;
+ static boolean mainRun = false;
+ static boolean useMSAA = true;
static int win_width = 1024;
static int win_height = 640;
+ static Font font;
+ static float fontSize = 24; // in pixel
+ static String customStr = null;
+
+ @BeforeClass
+ public static void setup() throws IOException {
+ if( null == font ) {
+ font = FontFactory.get(FontFactory.UBUNTU).getDefault();
+ // font = FontFactory.get(FontFactory.JAVA).getDefault();
+ }
+ }
+
static int atoi(final String a) {
try {
return Integer.parseInt(a);
@@ -71,6 +98,7 @@ public class TestTextRendererNEWT01 extends UITestCase {
}
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++;
@@ -81,6 +109,21 @@ public class TestTextRendererNEWT01 extends UITestCase {
} else if(args[i].equals("-height")) {
i++;
win_height = 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;
+ } else if(args[i].equals("-font")) {
+ i++;
+ font = FontFactory.get(IOUtil.getResource(args[i], TestTextRendererNEWT01.class.getClassLoader(), TestTextRendererNEWT01.class).getInputStream(), true);
+ } 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 = TestTextRendererNEWT01.class.getName();
@@ -94,218 +137,145 @@ public class TestTextRendererNEWT01 extends UITestCase {
} catch (final InterruptedException ie) {}
}
- static void destroyWindow(final GLWindow window) {
- if(null!=window) {
- window.destroy();
- }
+ @Test
+ public void test00TextRendererNONE00() throws InterruptedException, GLException, IOException {
+ testTextRendererImpl(0, 0);
}
- static GLWindow createWindow(final String title, final GLCapabilitiesImmutable caps, final int width, final int height) {
- Assert.assertNotNull(caps);
-
- final GLWindow window = GLWindow.create(caps);
- window.setSize(width, height);
- window.setPosition(10, 10);
- window.setTitle(title);
- Assert.assertNotNull(window);
- window.setVisible(true);
-
- return window;
+ @Test
+ public void test01TextRendererMSAA04() throws InterruptedException, GLException, IOException {
+ testTextRendererImpl(0, 4);
}
@Test
- public void testTextRendererR2T01() throws InterruptedException, GLException, IOException {
- if(Platform.CPUFamily.X86 != PlatformPropsImpl.CPU_ARCH.family) { // FIXME
- // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise).
- System.err.println("disabled on non desktop (x86) arch for now ..");
- return;
- }
- final GLProfile glp = GLProfile.getGL2ES2();
-
- final GLCapabilities caps = new GLCapabilities(glp);
- caps.setAlphaBits(4);
- System.err.println("Requested: "+caps);
-
- final GLWindow window = createWindow("text-vbaa1-msaa0", caps, win_width, win_height);
- window.display();
- System.err.println("Chosen: "+window.getChosenGLCapabilities());
+ public void test02TextRendererVBAA04() throws InterruptedException, GLException, IOException {
+ testTextRendererImpl(Region.VBAA_RENDERING_BIT, 4);
+ }
- final RenderState rs = RenderState.createRenderState(SVertex.factory());
- final TextGLListener textGLListener = new TextGLListener(rs, Region.VBAA_RENDERING_BIT, 4 /* sampleCount */, DEBUG, TRACE);
- textGLListener.attachInputListenerTo(window);
- window.addGLEventListener(textGLListener);
- textGLListener.setHeadBox(2, true);
- window.display();
- // final AABBox headbox = textGLListener.getHeadBox();
- // GPUTextRendererListenerBase01.upsizeWindowSurface(window, false, (int)(headbox.getWidth()*1.5f), (int)(headbox.getHeight()*2f));
-
- final Runnable action_per_font = new Runnable() {
- @Override
- public void run() {
- if( false ) {
- textGLListener.setHeadBox(1, false);
- textGLListener.setSampleCount(2);
- window.display();
- textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
- sleep();
-
- textGLListener.setHeadBox(2, false);
- textGLListener.setSampleCount(2);
- window.display();
- textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
- sleep();
- }
-
- textGLListener.setHeadBox(1, false);
- textGLListener.setSampleCount(4);
- window.display();
- textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
- sleep();
-
- textGLListener.setHeadBox(2, false);
- textGLListener.setSampleCount(4);
- window.display();
- textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
- sleep();
- } };
-
- final Font[] fonts = FontSet01.getSet01();
- for(final Font f : fonts) {
- if( textGLListener.setFont(f) ) {
- action_per_font.run();
- }
- }
- if(textGLListener.setFontSet(FontFactory.JAVA, 0, 0)) {
- action_per_font.run();
+ void testTextRendererImpl(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();
}
- destroyWindow(window);
- }
- @Test
- public void testTextRendererMSAA01() throws InterruptedException, GLException, IOException {
- final GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
- final GLCapabilities caps = new GLCapabilities(glp);
+ final GLCapabilities caps = new GLCapabilities( glp );
caps.setAlphaBits(4);
- caps.setSampleBuffers(true);
- caps.setNumSamples(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 GLWindow window = createWindow("text-vbaa0-msaa1", caps, 1024, 640);
- window.display();
- System.err.println("Chosen: "+window.getChosenGLCapabilities());
+ final NEWTGLContext.WindowContext winctx = NEWTGLContext.createWindow(caps, win_width, win_height, true);
+ final GLDrawable drawable = winctx.context.getGLDrawable();
+ final GL2ES2 gl = winctx.context.getGL().getGL2ES2();
- final RenderState rs = RenderState.createRenderState(SVertex.factory());
- final TextGLListener textGLListener = new TextGLListener(rs, 0, 0 /* sampleCount */, DEBUG, TRACE);
- textGLListener.attachInputListenerTo(window);
- window.addGLEventListener(textGLListener);
- textGLListener.setHeadBox(2, true);
- window.display();
-
- final Runnable action_per_font = new Runnable() {
- @Override
- public void run() {
- textGLListener.setHeadBox(1, false);
- textGLListener.setSampleCount(0);
- window.display();
- textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
- sleep();
-
- textGLListener.setHeadBox(2, false);
- textGLListener.setSampleCount(0);
- window.display();
- textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
- sleep();
- } };
-
- final Font[] fonts = FontSet01.getSet01();
- for(final Font f : fonts) {
- if( textGLListener.setFont(f) ) {
- action_per_font.run();
- }
- }
- if(textGLListener.setFontSet(FontFactory.JAVA, 0, 0)) {
- action_per_font.run();
- }
+ Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
- destroyWindow(window);
- }
-
- @Test
- public void testTextRendererNoSampling() throws InterruptedException, GLException, IOException {
- final GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
- final GLCapabilities caps = new GLCapabilities(glp);
- caps.setAlphaBits(4);
- System.err.println("Requested: "+caps);
-
- final GLWindow window = createWindow("text-vbaa0-msaa0", caps, 1024, 640);
- window.display();
- System.err.println("Chosen: "+window.getChosenGLCapabilities());
+ System.err.println("Chosen: "+winctx.window.getChosenCapabilities());
final RenderState rs = RenderState.createRenderState(SVertex.factory());
- final TextGLListener textGLListener = new TextGLListener(rs, 0, 0 /* sampleCount */, DEBUG, TRACE);
- textGLListener.attachInputListenerTo(window);
- window.addGLEventListener(textGLListener);
- textGLListener.setHeadBox(2, true);
- window.display();
-
- final Runnable action_per_font = new Runnable() {
- @Override
- public void run() {
- textGLListener.setHeadBox(1, false);
- textGLListener.setSampleCount(0);
- window.display();
- textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
- sleep();
-
- textGLListener.setHeadBox(2, false);
- textGLListener.setSampleCount(0);
- window.display();
- textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
- sleep();
- } };
-
- final Font[] fonts = FontSet01.getSet01();
- for(final Font f : fonts) {
- if( textGLListener.setFont(f) ) {
- action_per_font.run();
+ 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);
+ if( null == customStr ) {
+ {
+ final float[] pixelsPerMM = winctx.window.getPixelsPerMM(new float[2]);
+ final float[] dpi = FontScale.ppmmToPPI(pixelsPerMM, new float[2]);
+ final float mmSize = fontSize / pixelsPerMM[1];
+ final int unitsPerEM = font.getMetrics().getUnitsPerEM();
+ String txt = String.format("Resolution dpiV %.2f, %.2f px/mm", dpi[1], pixelsPerMM[1]);
+ renderString(drawable, gl, renderer, textRenderUtil, txt, 0, 0, -1000, sampleCountIO);
+ txt = String.format("Font %s, unitsPerEM %d, size %.2f px %2f mm", font.getFullFamilyName(), unitsPerEM, fontSize, mmSize);
+ renderString(drawable, gl, renderer, textRenderUtil, txt, 0, -1, -1000, sampleCountIO);
}
+ renderString(drawable, gl, renderer, textRenderUtil, "012345678901234567890123456789", 0, -1, -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);
}
- if(textGLListener.setFontSet(FontFactory.JAVA, 0, 0)) {
- action_per_font.run();
- }
+ gl.glFinish();
+ printScreen(renderModes, drawable, gl, false, sampleCount);
+ drawable.swapBuffers();
- destroyWindow(window);
- }
+ sleep();
- private static class TextGLListener extends GPUTextRendererListenerBase01 {
- public TextGLListener(final RenderState rs, final int type, final int sampleCount, final boolean debug, final boolean trace) {
- super(rs, type, sampleCount, true, debug, trace);
- }
+ // dispose
+ screenshot.dispose(gl);
+ renderer.destroy(gl);
- @Override
- public void attachInputListenerTo(final GLWindow window) {
- super.attachInputListenerTo(window);
- }
- public void setSampleCount(final int sampleCount){
- // setMatrix(xt, yt, zoom, angle, sampleCount);
- setMatrix(0, 0, 0, 0f, sampleCount);
- }
+ NEWTGLContext.destroyWindow(winctx);
+ }
- @Override
- public void init(final GLAutoDrawable drawable) {
- super.init(drawable);
+ private GLReadBufferUtil screenshot;
+ int lastRow = -1;
- final GL2ES2 gl = drawable.getGL().getGL2ES2();
- gl.setSwapInterval(1);
- gl.glEnable(GL.GL_DEPTH_TEST);
+ 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();
- final RenderState rs = getRenderer().getRenderState();
- rs.setColorStatic(0.1f, 0.1f, 0.1f, 1.0f);
+ float dx = 0;
+ float dy = height;
+ if(0>row) {
+ row = lastRow + 1;
}
+ final AABBox textBox = font.getMetricBounds(text); // em-size
+ dx += fontSize * font.getAdvanceWidth('X') * column;
+ dy -= fontSize * textBox.getHeight() * ( row + 1 );
+
+ final PMVMatrix pmv = renderer.getMatrix();
+ pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
+ pmv.glLoadIdentity();
+ pmv.glTranslatef(dx, dy, z0);
+ pmv.glScalef(fontSize, fontSize, 1.0f);
+ textRenderUtil.drawString3D(gl, renderer, font, text, null, sampleCount);
+
+ lastRow = row;
+ }
- @Override
- public void display(final GLAutoDrawable drawable) {
- super.display(drawable);
+ 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((Locale)null, "%s-msaa%02d-fontsz%02.1f-%03dx%03d-%s%04d", objName,
+ drawable.getChosenGLCapabilities().getNumSamples(),
+ 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/TestTextRendererNEWT10.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java
index 5cabe546d..63eb2be65 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2012 JogAmp Community. All rights reserved.
+ * Copyright 2011-2023 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:
@@ -29,62 +29,68 @@ package com.jogamp.opengl.test.junit.graph;
import java.io.File;
import java.io.IOException;
+import java.net.URL;
import java.util.Locale;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2ES2;
+import com.jogamp.opengl.GLAnimatorControl;
+import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
-import com.jogamp.opengl.GLDrawable;
+import com.jogamp.opengl.GLCapabilitiesImmutable;
import com.jogamp.opengl.GLException;
import com.jogamp.opengl.GLProfile;
-import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
+import com.jogamp.opengl.GLRunnable;
import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
import org.junit.FixMethodOrder;
+import org.junit.Test;
import org.junit.runners.MethodSorters;
-import com.jogamp.common.util.IOUtil;
+import com.jogamp.common.os.Platform;
import com.jogamp.graph.curve.Region;
-import com.jogamp.graph.curve.opengl.RenderState;
+import com.jogamp.graph.curve.opengl.GLRegion;
import com.jogamp.graph.curve.opengl.RegionRenderer;
-import com.jogamp.graph.curve.opengl.TextRegionUtil;
+import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontFactory;
import com.jogamp.graph.font.FontScale;
import com.jogamp.graph.geom.SVertex;
-import com.jogamp.opengl.math.geom.AABBox;
+import com.jogamp.junit.util.JunitTracer;
+import com.jogamp.newt.Window;
+import com.jogamp.newt.opengl.GLWindow;
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.Animator;
import com.jogamp.opengl.util.GLReadBufferUtil;
-import com.jogamp.opengl.util.PMVMatrix;
+/**
+ * TestTextRendererNEWT10 Variant
+ * - Using listener derived from rudimentary TextRendererGLELBase, w/o much functionality but scaling ..
+ * - Type Rendering via TextRegionUtil, multiple
+ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestTextRendererNEWT10 extends UITestCase {
static final boolean DEBUG = false;
static final boolean TRACE = false;
- static long duration = 100; // ms
- static boolean forceES2 = false;
- static boolean forceGL3 = false;
- static boolean mainRun = false;
- static boolean useMSAA = true;
+ static long Duration = 2000; // ms
static int win_width = 1024;
static int win_height = 640;
-
- static Font font;
- static float fontSize = 24; // in pixel
- static String customStr = null;
-
- @BeforeClass
- public static void setup() throws IOException {
- if( null == font ) {
- font = FontFactory.get(FontFactory.UBUNTU).getDefault();
- // font = FontFactory.get(FontFactory.JAVA).getDefault();
- }
- }
+ static boolean WaitStartEnd = false;
+ static boolean TextAnim = false;
+ static int SceneMSAASamples = 0;
+ static int GraphVBAASamples = 0;
+ static int GraphMSAASamples = 0;
+ static boolean ManualTest = false;
+ static int SwapInterval = 1;
+
+ static String fontFileName = null;
+ static URL fontURL = null;
+ static int fontSet = 0;
+ static int fontFamily = 0;
+ static int fontStylebits = 0;
+ static float fontSizeFixed = 14f;
static int atoi(final String a) {
try {
@@ -93,184 +99,343 @@ public class TestTextRendererNEWT10 extends UITestCase {
}
public static void main(final String args[]) throws IOException {
- mainRun = true;
+ ManualTest = args.length > 0;
for(int i=0; i<args.length; i++) {
if(args[i].equals("-time")) {
i++;
- duration = atoi(args[i]);
+ Duration = atoi(args[i]);
} else if(args[i].equals("-width")) {
i++;
win_width = atoi(args[i]);
} else if(args[i].equals("-height")) {
i++;
win_height = 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;
- } else if(args[i].equals("-font")) {
+ } else if(args[i].equals("-fontURL")) {
+ i++;
+ fontURL = new URL(args[i]);
+ } else if(args[i].equals("-fontFile")) {
+ i++;
+ fontFileName = args[i];
+ } else if(args[i].equals("-fontSet")) {
i++;
- font = FontFactory.get(IOUtil.getResource(args[i], TestTextRendererNEWT10.class.getClassLoader(), TestTextRendererNEWT10.class).getInputStream(), true);
+ fontSet = atoi(args[i]);
+ } else if(args[i].equals("-fontFamily")) {
+ i++;
+ fontFamily = atoi(args[i]);
+ } else if(args[i].equals("-fontStyle")) {
+ i++;
+ fontStylebits = atoi(args[i]);
} else if(args[i].equals("-fontSize")) {
i++;
- fontSize = MiscUtils.atof(args[i], fontSize);
- } else if(args[i].equals("-text")) {
+ fontSizeFixed = atoi(args[i]);
+ } else if(args[i].equals("-smsaa")) {
+ i++;
+ SceneMSAASamples = atoi(args[i]);
+ } else if(args[i].equals("-gmsaa")) {
+ i++;
+ GraphMSAASamples = atoi(args[i]);
+ } else if(args[i].equals("-gvbaa")) {
i++;
- customStr = args[i];
+ GraphVBAASamples = atoi(args[i]);
+ } else if(args[i].equals("-textAnim")) {
+ TextAnim = true;
+ } else if(args[i].equals("-vsync")) {
+ i++;
+ SwapInterval = MiscUtils.atoi(args[i], SwapInterval);
+ } else if(args[i].equals("-wait")) {
+ WaitStartEnd = true;
}
}
+ System.err.println("Font [set "+fontSet+", family "+fontFamily+", style "+fontStylebits+", size "+fontSizeFixed+"], fontFileName "+fontFileName);
+ System.err.println("Scene MSAA Samples "+SceneMSAASamples);
+ System.err.println("Graph MSAA Samples "+GraphMSAASamples);
+ System.err.println("Graph VBAA Samples "+GraphVBAASamples);
+ System.err.println("swapInterval "+SwapInterval);
final String tstname = TestTextRendererNEWT10.class.getName();
org.junit.runner.JUnitCore.main(tstname);
}
static void sleep() {
+ sleep(Duration);
+ }
+ static void sleep(final long d) {
try {
- System.err.println("** new frame ** (sleep: "+duration+"ms)");
- Thread.sleep(duration);
+ System.err.println("** new frame ** (sleep: "+d+"ms)");
+ Thread.sleep(d);
} catch (final InterruptedException ie) {}
}
- @Test
- public void test00TextRendererNONE00() throws InterruptedException, GLException, IOException {
- testTextRendererImpl(0, 0);
+ static void destroyWindow(final GLWindow window) {
+ if(null!=window) {
+ window.destroy();
+ }
}
- @Test
- public void test01TextRendererMSAA04() throws InterruptedException, GLException, IOException {
- testTextRendererImpl(0, 4);
+ static GLWindow createWindow(final String title, final GLCapabilitiesImmutable caps, final int width, final int height) {
+ Assert.assertNotNull(caps);
+
+ final GLWindow window = GLWindow.create(caps);
+ window.setSize(width, height);
+ window.setPosition(10, 10);
+ window.setTitle(title);
+ Assert.assertNotNull(window);
+ window.setVisible(true);
+
+ return window;
}
@Test
- public void test02TextRendererVBAA04() throws InterruptedException, GLException, IOException {
- testTextRendererImpl(Region.VBAA_RENDERING_BIT, 4);
+ public void test00Manual() throws InterruptedException {
+ if( ManualTest ) {
+ testImpl(SceneMSAASamples, GraphMSAASamples, GraphVBAASamples);
+ }
+ }
+ @Test
+ public void test00SceneNoAA() throws InterruptedException {
+ if( !ManualTest ) {
+ testImpl(0, 0, 0);
+ }
}
-
- void testTextRendererImpl(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();
+ @Test
+ public void test01SceneMSAA04() throws InterruptedException {
+ if( !ManualTest ) {
+ testImpl(4, 0, 0);
}
+ }
+ @Test
+ public void test02GraphMSAA04() throws InterruptedException {
+ if( !ManualTest ) {
+ testImpl(0, 4, 0);
+ }
+ }
+ @Test
+ public void test03GraphVBAA04() throws InterruptedException {
+ if( !ManualTest ) {
+ testImpl(0, 0, 4);
+ }
+ }
- final GLCapabilities caps = new GLCapabilities( glp );
+ public void testImpl(final int sceneMSAASamples, final int graphMSAASamples, final int graphVBAASamples) throws InterruptedException {
+ final GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
+ final GLCapabilities caps = new GLCapabilities(glp);
caps.setAlphaBits(4);
- if( 0 < sampleCount && !Region.isVBAA(renderModes) ) {
+ if( 0 < sceneMSAASamples ) {
caps.setSampleBuffers(true);
- caps.setNumSamples(sampleCount);
+ caps.setNumSamples(sceneMSAASamples);
}
- System.err.println("Requested: "+caps);
- System.err.println("Requested: "+Region.getRenderModeString(renderModes));
-
- final NEWTGLContext.WindowContext winctx = NEWTGLContext.createWindow(caps, win_width, win_height, true);
- final GLDrawable drawable = winctx.context.getGLDrawable();
- final GL2ES2 gl = winctx.context.getGL().getGL2ES2();
+ System.err.println("Requested: "+caps+", graph[msaaSamples "+graphMSAASamples+", vbaaSamples "+graphVBAASamples+"]");
- Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
+ final GLWindow window = createWindow("text-gvbaa"+graphVBAASamples+"-gmsaa"+graphMSAASamples+"-smsaa"+sceneMSAASamples, caps, win_width, win_height);
- System.err.println("Chosen: "+winctx.window.getChosenCapabilities());
+ window.display();
+ System.err.println("Chosen: "+window.getChosenGLCapabilities());
+ if( WaitStartEnd ) {
+ JunitTracer.waitForKey("Start");
+ }
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);
- if( null == customStr ) {
- {
- final float[] pixelsPerMM = winctx.window.getPixelsPerMM(new float[2]);
- final float[] dpi = FontScale.ppmmToPPI(pixelsPerMM, new float[2]);
- final float mmSize = fontSize / pixelsPerMM[1];
- final int unitsPerEM = font.getMetrics().getUnitsPerEM();
- String txt = String.format("Resolution dpiV %.2f, %.2f px/mm", dpi[1], pixelsPerMM[1]);
- renderString(drawable, gl, renderer, textRenderUtil, txt, 0, 0, -1000, sampleCountIO);
- txt = String.format("Font %s, unitsPerEM %d, size %.2f px %2f mm", font.getFullFamilyName(), unitsPerEM, fontSize, mmSize);
- renderString(drawable, gl, renderer, textRenderUtil, txt, 0, -1, -1000, sampleCountIO);
- }
- renderString(drawable, gl, renderer, textRenderUtil, "012345678901234567890123456789", 0, -1, -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);
+ final int renderModes, sampleCount;
+ if( graphVBAASamples > 0 ) {
+ renderModes = Region.VBAA_RENDERING_BIT;
+ sampleCount = graphVBAASamples;
+ } else if ( graphMSAASamples > 0 ) {
+ renderModes = Region.MSAA_RENDERING_BIT;
+ sampleCount = graphMSAASamples;
} else {
- renderString(drawable, gl, renderer, textRenderUtil, customStr, 0, 0, -1000, sampleCountIO);
+ renderModes = 0;
+ sampleCount = 0;
}
- gl.glFinish();
- printScreen(renderModes, drawable, gl, false, sampleCount);
- drawable.swapBuffers();
+ final TextRendererGLEL textGLListener = new TextRendererGLEL(rs, renderModes, sampleCount);
+ System.err.println(textGLListener.getFontInfo());
- sleep();
-
- // dispose
- screenshot.dispose(gl);
- renderer.destroy(gl);
+ window.addGLEventListener(textGLListener);
- NEWTGLContext.destroyWindow(winctx);
+ final Animator anim = new Animator();
+ anim.add(window);
+ anim.start();
+ anim.setUpdateFPSFrames(60, null);
+ sleep();
+ window.invoke(true, new GLRunnable() {
+ @Override
+ public boolean run(final GLAutoDrawable drawable) {
+ try {
+ textGLListener.printScreen(renderModes, drawable, "./", "TestTextRendererNEWT00-snap"+screenshot_num, false);
+ screenshot_num++;
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+ return true;
+ }
+ });
+ anim.stop();
+ if( WaitStartEnd ) {
+ JunitTracer.waitForKey("Stop");
+ }
+ destroyWindow(window);
}
+ int screenshot_num = 0;
+
+ static final String textX2 =
+ "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec sapien tellus. \n"+
+ "Ut purus odio, rhoncus sit amet commodo eget, ullamcorper vel urna. Mauris ultricies \n"+
+ "quam iaculis urna cursus ornare. Nullam ut felis a ante ultrices ultricies nec a elit. \n"+
+ "In hac habitasse platea dictumst. Vivamus et mi a quam lacinia pharetra at venenatis est.\n"+
+ "Morbi quis bibendum nibh. Donec lectus orci, sagittis in consequat nec, volutpat nec nisi.\n"+
+ "Donec ut dolor et nulla tristique varius. In nulla magna, fermentum id tempus quis, semper \n"+
+ "in lorem. Maecenas in ipsum ac justo scelerisque sollicitudin. Quisque sit amet neque lorem,\n" +
+ "-------Press H to change text---------\n";
+
+ private static final class TextRendererGLEL extends TextRendererGLELBase {
+ private final GLReadBufferUtil screenshot;
+ private final GLRegion regionFPS, regionFPSAnim;
+ final Font font;
+ final float fontSizeMin, fontSizeMax;
+ private long t0;
+ float fontSizeAnim, fontSizeDelta;
+ float dpiV, ppmmV;
+
+ TextRendererGLEL(final RenderState rs, final int renderModes, final int sampleCount) {
+ super(renderModes, new int[] { sampleCount });
+ setRendererCallbacks(RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
+ setRenderState(rs);
+
+ regionFPS = GLRegion.create(renderModes, null);
+ regionFPSAnim = GLRegion.create(renderModes, null);
+ if( null != fontURL ) {
+ Font _font = null;
+ try {
+ _font = FontFactory.get(fontURL.openStream(), true);
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+ font = _font;
+ } else if( null != fontFileName ) {
+ Font _font = null;
+ try {
+ _font = FontFactory.get(getClass(), fontFileName, false);
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+ font = _font;
+ } else {
+ font = getFont(fontSet, fontFamily, fontStylebits);
+ }
- private GLReadBufferUtil screenshot;
- int lastRow = -1;
+ staticRGBAColor[0] = 0.1f;
+ staticRGBAColor[1] = 0.1f;
+ staticRGBAColor[2] = 0.1f;
+ staticRGBAColor[3] = 1.0f;
+
+ this.screenshot = new GLReadBufferUtil(false, false);
+ // fontSizeMin = Math.max(8, fontSizeFixed-5);
+ fontSizeMin = fontSizeFixed;
+ fontSizeMax = fontSizeFixed+8;
+ fontSizeAnim = fontSizeFixed;
+ fontSizeDelta = 0.01f;
+ }
- 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();
+ @Override
+ public void init(final GLAutoDrawable drawable) {
+ super.init(drawable);
+ final GL2ES2 gl = drawable.getGL().getGL2ES2();
+ gl.setSwapInterval(SwapInterval);
+ gl.glEnable(GL.GL_DEPTH_TEST);
+ t0 = Platform.currentTimeMillis();
+
+ final Window win = (Window)drawable.getUpstreamWidget();
+ final float[] pixelsPerMM = win.getPixelsPerMM(new float[2]);
+ final float[] dotsPerInch = FontScale.ppmmToPPI(pixelsPerMM, new float[2]);
+ dpiV = dotsPerInch[1];
+ ppmmV = pixelsPerMM[1];
+ System.err.println(getFontInfo());
+ System.err.println("fontSize "+fontSizeFixed+", dotsPerMM "+pixelsPerMM[0]+"x"+pixelsPerMM[1]+", dpi "+dotsPerInch[0]+"x"+dotsPerInch[1]+", pixelSize "+FontScale.toPixels(fontSizeFixed, dotsPerInch[1] /* dpi display */));
+ }
- float dx = 0;
- float dy = height;
- if(0>row) {
- row = lastRow + 1;
+ @Override
+ public void dispose(final GLAutoDrawable drawable) {
+ final GL2ES2 gl = drawable.getGL().getGL2ES2();
+ screenshot.dispose(gl);
+ regionFPS.destroy(gl);
+ regionFPSAnim.destroy(gl);
+ super.dispose(drawable);
}
- final AABBox textBox = font.getMetricBounds(text); // em-size
- dx += fontSize * font.getAdvanceWidth('X') * column;
- dy -= fontSize * textBox.getHeight() * ( row + 1 );
-
- final PMVMatrix pmv = renderer.getMatrix();
- pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
- pmv.glLoadIdentity();
- pmv.glTranslatef(dx, dy, z0);
- pmv.glScalef(fontSize, fontSize, 1.0f);
- textRenderUtil.drawString3D(gl, renderer, font, 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((Locale)null, "%s-msaa%02d-fontsz%02.1f-%03dx%03d-%s%04d", objName,
- drawable.getChosenGLCapabilities().getNumSamples(),
- fontSize, drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), modeS, sampleCount);
- final String filename = dir + bname +".png";
- if(screenshot.readPixels(gl, false)) {
- screenshot.write(new File(filename));
+ public void printScreen(final int renderModes, final GLAutoDrawable drawable, final String dir, final String objName, final boolean exportAlpha) throws GLException, IOException {
+ final String modeS = Region.getRenderModeString(renderModes);
+ final String bname = String.format((Locale)null, "%s-msaa%02d-fontsz%02.1f-%03dx%03d-%s%04d", objName,
+ drawable.getChosenGLCapabilities().getNumSamples(),
+ fontSizeFixed, drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), modeS, vbaaSampleCount[0]);
+ final String filename = dir + bname +".png";
+ if(screenshot.readPixels(drawable.getGL(), false)) {
+ screenshot.write(new File(filename));
+ }
}
- }
+
+ String getFontInfo() {
+ final float pixelSize = FontScale.toPixels(fontSizeFixed, dpiV);
+ final float mmSize = pixelSize / ppmmV;
+ final int unitsPerEM = font.getMetrics().getUnitsPerEM();
+ return String.format("Resolution dpiV %.2f, %.2f px/mm%nFont %s, unitsPerEM %d, size %.2f pt %.2f px %2f mm%n",
+ dpiV, ppmmV,
+ font.getFullFamilyName(),unitsPerEM, fontSizeFixed, pixelSize, mmSize);
+ }
+
+ @Override
+ public void display(final GLAutoDrawable drawable) {
+ final 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);
+
+ final GLAnimatorControl anim = drawable.getAnimator();
+ final float lfps = null != anim ? anim.getLastFPS() : 0f;
+ final float tfps = null != anim ? anim.getTotalFPS() : 0f;
+
+ // Note: MODELVIEW is from [ 0 .. height ]
+
+ final long t1 = Platform.currentTimeMillis();
+
+ // final float fontSize = TestTextRendererNEWT00.fontSize;
+
+ fontSizeAnim += fontSizeDelta;
+ if( fontSizeMin >= fontSizeAnim || fontSizeAnim >= fontSizeMax ) {
+ fontSizeDelta *= -1f;
+ }
+
+ final float pixelSize = FontScale.toPixels(fontSizeFixed, dpiV);
+ final float pixelSizeAnim = FontScale.toPixels(fontSizeAnim, dpiV);
+
+ final String modeS = Region.getRenderModeString(renderModes);
+
+ if( false ) {
+ // renderString(drawable, font, pixelSize, "I - / H P 7 0", 0, 0, 0, 0, -1000f, true);
+ // renderString(drawable, font, pixelSize, "A M > } ] ", 0, 0, 0, 0, -1000f, true);
+ // renderString(drawable, font, pixelSize, "M", 0, 0, 0, 0, -1000f, true);
+ // renderString(drawable, font, pixelSize, "0 6 9 a b O Q A M > } ] ", 0, 0, 0, 0, -1000f, true);
+ // renderString(drawable, font, pixelSize, "012345678901234567890123456789", 0, 0, 0, -1000, true);
+ // renderString(drawable, font, pixelSize, textX2, 0, 0, 0, 0, -1000f, true);
+ // renderString(drawable, font, pixelSize, text1, 0, 0, 0, -1000f, regionFPS); // no-cache
+ final String text1 = lfps+" / "+tfps+" fps, vsync "+gl.getSwapInterval()+", elapsed "+(t1-t0)/1000.0+
+ " s, fontSize "+fontSizeFixed+", msaa "+drawable.getChosenGLCapabilities().getNumSamples()+
+ ", "+modeS+"-samples "+vbaaSampleCount[0];
+ renderString(drawable, font, pixelSize, text1, 0, 0, 0, 0, -1000, regionFPS); // no-cache
+ } else {
+ final String text1 = String.format("%03.1f/%03.1f fps, vsync %d, elapsed %4.1f s, fontSize %2.2f, msaa %d, %s-samples %d",
+ lfps, tfps, gl.getSwapInterval(), (t1-t0)/1000.0, fontSizeFixed,
+ drawable.getChosenGLCapabilities().getNumSamples(), modeS, vbaaSampleCount[0]);
+ renderString(drawable, font, pixelSize, getFontInfo(), 0, 0, 0, 0, -1000, true);
+ renderString(drawable, font, pixelSize, "012345678901234567890123456789", 0, 0, 0, -1000, true);
+ renderString(drawable, font, pixelSize, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, 0, 0, -1000, true);
+ renderString(drawable, font, pixelSize, "Hello World", 0, 0, 0, -1000, true);
+ renderString(drawable, font, pixelSize, "4567890123456", 4, 0, 0, -1000, true);
+ renderString(drawable, font, pixelSize, "I like JogAmp", 4, 0, 0, -1000, true);
+ renderString(drawable, font, pixelSize, "Hello World", 0, 0, 0, -1000, true);
+ renderString(drawable, font, pixelSize, textX2, 0, 0, 0, -1000, true);
+ renderString(drawable, font, pixelSize, text1, 0, 0, 0, -1000, regionFPS); // no-cache
+ if( TextAnim ) {
+ renderString(drawable, font, pixelSizeAnim, text1, 0, 0, 0, -1000, regionFPSAnim); // no-cache
+ }
+ }
+ } };
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT20.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT20.java
new file mode 100644
index 000000000..04604095f
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT20.java
@@ -0,0 +1,316 @@
+/**
+ * Copyright 2011-2023 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 com.jogamp.opengl.GL;
+import com.jogamp.opengl.GL2ES2;
+import com.jogamp.opengl.GLAutoDrawable;
+import com.jogamp.opengl.GLCapabilities;
+import com.jogamp.opengl.GLCapabilitiesImmutable;
+import com.jogamp.opengl.GLException;
+import com.jogamp.opengl.GLProfile;
+
+import jogamp.common.os.PlatformPropsImpl;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.FixMethodOrder;
+import org.junit.runners.MethodSorters;
+
+import com.jogamp.common.os.Platform;
+import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.RenderState;
+import com.jogamp.graph.font.Font;
+import com.jogamp.graph.font.FontFactory;
+import com.jogamp.graph.geom.SVertex;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.test.junit.graph.demos.GPUTextRendererListenerBase01;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+
+/**
+ * TestTextRendererNEWT20 Variant
+ * - Using listener derived from fully features GPUTextRendererListenerBase01
+ * - Renders multiple demo text with multiple fonts
+ * - Used for validation against reference
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestTextRendererNEWT20 extends UITestCase {
+ static final boolean DEBUG = false;
+ static final boolean TRACE = false;
+ static long duration = 100; // ms
+ static int win_width = 1024;
+ static int win_height = 640;
+
+ 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 {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ duration = atoi(args[i]);
+ } else if(args[i].equals("-width")) {
+ i++;
+ win_width = atoi(args[i]);
+ } else if(args[i].equals("-height")) {
+ i++;
+ win_height = atoi(args[i]);
+ }
+ }
+ final String tstname = TestTextRendererNEWT20.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) {}
+ }
+
+ static void destroyWindow(final GLWindow window) {
+ if(null!=window) {
+ window.destroy();
+ }
+ }
+
+ static GLWindow createWindow(final String title, final GLCapabilitiesImmutable caps, final int width, final int height) {
+ Assert.assertNotNull(caps);
+
+ final GLWindow window = GLWindow.create(caps);
+ window.setSize(width, height);
+ window.setPosition(10, 10);
+ window.setTitle(title);
+ Assert.assertNotNull(window);
+ window.setVisible(true);
+
+ return window;
+ }
+
+ @Test
+ public void testTextRendererR2T01() throws InterruptedException, GLException, IOException {
+ if(Platform.CPUFamily.X86 != PlatformPropsImpl.CPU_ARCH.family) { // FIXME
+ // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise).
+ System.err.println("disabled on non desktop (x86) arch for now ..");
+ return;
+ }
+ final GLProfile glp = GLProfile.getGL2ES2();
+
+ final GLCapabilities caps = new GLCapabilities(glp);
+ caps.setAlphaBits(4);
+ System.err.println("Requested: "+caps);
+
+ final GLWindow window = createWindow("text-vbaa1-msaa0", caps, win_width, win_height);
+ window.display();
+ System.err.println("Chosen: "+window.getChosenGLCapabilities());
+
+ final RenderState rs = RenderState.createRenderState(SVertex.factory());
+ final TextGLListener textGLListener = new TextGLListener(rs, Region.VBAA_RENDERING_BIT, 4 /* sampleCount */, DEBUG, TRACE);
+ textGLListener.attachInputListenerTo(window);
+ window.addGLEventListener(textGLListener);
+ textGLListener.setHeadBox(2, true);
+ window.display();
+ // final AABBox headbox = textGLListener.getHeadBox();
+ // GPUTextRendererListenerBase01.upsizeWindowSurface(window, false, (int)(headbox.getWidth()*1.5f), (int)(headbox.getHeight()*2f));
+
+ final Runnable action_per_font = new Runnable() {
+ @Override
+ public void run() {
+ if( false ) {
+ textGLListener.setHeadBox(1, false);
+ textGLListener.setSampleCount(2);
+ window.display();
+ textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
+ sleep();
+
+ textGLListener.setHeadBox(2, false);
+ textGLListener.setSampleCount(2);
+ window.display();
+ textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
+ sleep();
+ }
+
+ textGLListener.setHeadBox(1, false);
+ textGLListener.setSampleCount(4);
+ window.display();
+ textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
+ sleep();
+
+ textGLListener.setHeadBox(2, false);
+ textGLListener.setSampleCount(4);
+ window.display();
+ textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
+ sleep();
+ } };
+
+ final Font[] fonts = FontSet01.getSet01();
+ for(final Font f : fonts) {
+ if( textGLListener.setFont(f) ) {
+ action_per_font.run();
+ }
+ }
+ if(textGLListener.setFontSet(FontFactory.JAVA, 0, 0)) {
+ action_per_font.run();
+ }
+ destroyWindow(window);
+ }
+
+ @Test
+ public void testTextRendererMSAA01() throws InterruptedException, GLException, IOException {
+ final GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
+ final GLCapabilities caps = new GLCapabilities(glp);
+ caps.setAlphaBits(4);
+ caps.setSampleBuffers(true);
+ caps.setNumSamples(4);
+ System.err.println("Requested: "+caps);
+
+ final GLWindow window = createWindow("text-vbaa0-msaa1", caps, 1024, 640);
+ window.display();
+ System.err.println("Chosen: "+window.getChosenGLCapabilities());
+
+ final RenderState rs = RenderState.createRenderState(SVertex.factory());
+ final TextGLListener textGLListener = new TextGLListener(rs, 0, 0 /* sampleCount */, DEBUG, TRACE);
+ textGLListener.attachInputListenerTo(window);
+ window.addGLEventListener(textGLListener);
+ textGLListener.setHeadBox(2, true);
+ window.display();
+
+ final Runnable action_per_font = new Runnable() {
+ @Override
+ public void run() {
+ textGLListener.setHeadBox(1, false);
+ textGLListener.setSampleCount(0);
+ window.display();
+ textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
+ sleep();
+
+ textGLListener.setHeadBox(2, false);
+ textGLListener.setSampleCount(0);
+ window.display();
+ textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
+ sleep();
+ } };
+
+ final Font[] fonts = FontSet01.getSet01();
+ for(final Font f : fonts) {
+ if( textGLListener.setFont(f) ) {
+ action_per_font.run();
+ }
+ }
+ if(textGLListener.setFontSet(FontFactory.JAVA, 0, 0)) {
+ action_per_font.run();
+ }
+
+ destroyWindow(window);
+ }
+
+ @Test
+ public void testTextRendererNoSampling() throws InterruptedException, GLException, IOException {
+ final GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
+ final GLCapabilities caps = new GLCapabilities(glp);
+ caps.setAlphaBits(4);
+ System.err.println("Requested: "+caps);
+
+ final GLWindow window = createWindow("text-vbaa0-msaa0", caps, 1024, 640);
+ window.display();
+ System.err.println("Chosen: "+window.getChosenGLCapabilities());
+
+ final RenderState rs = RenderState.createRenderState(SVertex.factory());
+ final TextGLListener textGLListener = new TextGLListener(rs, 0, 0 /* sampleCount */, DEBUG, TRACE);
+ textGLListener.attachInputListenerTo(window);
+ window.addGLEventListener(textGLListener);
+ textGLListener.setHeadBox(2, true);
+ window.display();
+
+ final Runnable action_per_font = new Runnable() {
+ @Override
+ public void run() {
+ textGLListener.setHeadBox(1, false);
+ textGLListener.setSampleCount(0);
+ window.display();
+ textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
+ sleep();
+
+ textGLListener.setHeadBox(2, false);
+ textGLListener.setSampleCount(0);
+ window.display();
+ textGLListener.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
+ sleep();
+ } };
+
+ final Font[] fonts = FontSet01.getSet01();
+ for(final Font f : fonts) {
+ if( textGLListener.setFont(f) ) {
+ action_per_font.run();
+ }
+ }
+ if(textGLListener.setFontSet(FontFactory.JAVA, 0, 0)) {
+ action_per_font.run();
+ }
+
+ destroyWindow(window);
+ }
+
+ private static class TextGLListener extends GPUTextRendererListenerBase01 {
+ public TextGLListener(final RenderState rs, final int type, final int sampleCount, final boolean debug, final boolean trace) {
+ super(rs, type, sampleCount, true, debug, trace);
+ }
+
+ @Override
+ public void attachInputListenerTo(final GLWindow window) {
+ super.attachInputListenerTo(window);
+ }
+ public void setSampleCount(final int sampleCount){
+ // setMatrix(xt, yt, zoom, angle, sampleCount);
+ setMatrix(0, 0, 0, 0f, sampleCount);
+ }
+
+ @Override
+ public void init(final GLAutoDrawable drawable) {
+ super.init(drawable);
+
+ final GL2ES2 gl = drawable.getGL().getGL2ES2();
+ gl.setSwapInterval(1);
+ gl.glEnable(GL.GL_DEPTH_TEST);
+
+ final RenderState rs = getRenderer().getRenderState();
+ rs.setColorStatic(0.1f, 0.1f, 0.1f, 1.0f);
+ }
+
+ @Override
+ public void display(final GLAutoDrawable drawable) {
+ super.display(drawable);
+ }
+ }
+}