aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--make/scripts/tests.sh6
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java125
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/Region.java84
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderUtil.java332
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java199
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java13
-rw-r--r--src/jogl/classes/com/jogamp/graph/font/Font.java9
-rw-r--r--src/jogl/classes/com/jogamp/graph/geom/Outline.java9
-rw-r--r--src/jogl/classes/com/jogamp/graph/geom/SVertex.java (renamed from src/jogl/classes/com/jogamp/graph/geom/opengl/SVertex.java)62
-rw-r--r--src/jogl/classes/com/jogamp/graph/geom/Triangle.java67
-rw-r--r--src/jogl/classes/com/jogamp/graph/geom/Vertex.java4
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java108
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java49
-rw-r--r--src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java45
-rw-r--r--src/jogl/classes/jogamp/graph/curve/tess/Loop.java6
-rw-r--r--src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java112
-rw-r--r--src/jogl/classes/jogamp/graph/curve/text/GlyphString.java234
-rw-r--r--src/jogl/classes/jogamp/graph/font/FontInt.java3
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java15
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java27
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java137
-rw-r--r--src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java32
-rw-r--r--src/jogl/classes/jogamp/graph/geom/plane/Path2D.java2
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java8
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java184
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java75
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java99
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java34
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java2
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java2
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java89
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextGLListener0A.java28
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java3
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java2
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java152
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java164
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java2
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo02.java2
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java51
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java72
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java2
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java37
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java2
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java66
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UITextShape.java4
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/opengl/UIRegion.java31
46 files changed, 1420 insertions, 1371 deletions
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh
index 8b1b79771..ad7222bc5 100644
--- a/make/scripts/tests.sh
+++ b/make/scripts/tests.sh
@@ -229,6 +229,8 @@ function jrun() {
#D_ARGS="-Dnativewindow.osx.calayer.bugfree"
#D_ARGS="-Dnativewindow.debug.ToolkitLock"
#D_ARGS="-Djogl.debug.graph.curve"
+ #D_ARGS="-Djogl.debug.graph.curve -Djogl.debug.graph.curve.instance"
+ #D_ARGS="-Djogl.debug.graph.curve.instance"
#D_ARGS="-Djogl.debug.graph.curve -Djogl.debug.GLSLCode -Djogl.debug.TraceGL"
#D_ARGS="-Djogl.debug.graph.curve -Djogl.debug.GLSLState"
#D_ARGS="-Djogamp.debug.TempJarCache -Djogamp.debug.JarUtil -Djogamp.debug.IOUtil"
@@ -728,8 +730,8 @@ function testawtswt() {
#
# Graph
#
-#testnoawt com.jogamp.opengl.test.junit.graph.TestTextRendererNEWT00 $*
-testnoawt com.jogamp.opengl.test.junit.graph.TestRegionRendererNEWT01 $*
+#testnoawt com.jogamp.opengl.test.junit.graph.TestRegionRendererNEWT01 $*
+testnoawt com.jogamp.opengl.test.junit.graph.TestTextRendererNEWT00 $*
#testnoawt com.jogamp.opengl.test.junit.graph.TestTextRendererNEWT01 $*
#testnoawt com.jogamp.opengl.test.junit.graph.TestTextRendererNEWTPerf01 $*
#testnoawt com.jogamp.opengl.test.junit.graph.TestTextRendererNEWT10 $*
diff --git a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
index c8d5a9db6..ee1dae4ca 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
@@ -107,15 +107,27 @@ public class OutlineShape implements Comparable<OutlineShape> {
}
public static final int DIRTY_BOUNDS = 1 << 0;
+ /**
+ * Modified shape, requires to update the vertices and triangles, here: vertices.
+ */
+ public static final int DIRTY_VERTICES = 1 << 1;
+ /**
+ * Modified shape, requires to update the vertices and triangles, here: triangulation.
+ */
+ public static final int DIRTY_TRIANGLES = 1 << 2;
private final Vertex.Factory<? extends Vertex> vertexFactory;
- private VerticesState outlineState;
/** The list of {@link Outline}s that are part of this
* outline shape.
*/
- /* pp */ ArrayList<Outline> outlines;
+ /* pp */ final ArrayList<Outline> outlines;
+
private final AABBox bbox;
+ private final ArrayList<Triangle> triangles;
+ private final ArrayList<Vertex> vertices;
+
+ private VerticesState outlineState;
/** dirty bits DIRTY_BOUNDS */
private int dirtyBits;
@@ -128,6 +140,8 @@ public class OutlineShape implements Comparable<OutlineShape> {
this.outlines.add(new Outline());
this.outlineState = VerticesState.UNDEFINED;
this.bbox = new AABBox();
+ this.triangles = new ArrayList<Triangle>();
+ this.vertices = new ArrayList<Vertex>();
this.dirtyBits = 0;
}
@@ -137,6 +151,8 @@ public class OutlineShape implements Comparable<OutlineShape> {
outlines.add(new Outline());
outlineState = VerticesState.UNDEFINED;
bbox.reset();
+ vertices.clear();
+ triangles.clear();
dirtyBits = 0;
}
@@ -200,6 +216,8 @@ public class OutlineShape implements Comparable<OutlineShape> {
if( 0 == ( dirtyBits & DIRTY_BOUNDS ) ) {
bbox.resize(outline.getBounds());
}
+ // vertices.addAll(outline.getVertices()); // FIXME: can do and remove DIRTY_VERTICES ?
+ dirtyBits |= DIRTY_TRIANGLES | DIRTY_VERTICES;
return;
}
}
@@ -207,6 +225,7 @@ public class OutlineShape implements Comparable<OutlineShape> {
if( 0 == ( dirtyBits & DIRTY_BOUNDS ) ) {
bbox.resize(outline.getBounds());
}
+ dirtyBits |= DIRTY_TRIANGLES | DIRTY_VERTICES;
}
/** Insert the {@link OutlineShape} elements of type {@link Outline}, .. at the end of this shape,
@@ -239,7 +258,7 @@ public class OutlineShape implements Comparable<OutlineShape> {
throw new NullPointerException("outline is null");
}
outlines.set(position, outline);
- dirtyBits |= DIRTY_BOUNDS;
+ dirtyBits |= DIRTY_BOUNDS | DIRTY_TRIANGLES | DIRTY_VERTICES;
}
/** Removes the {@link Outline} element at the given {@code position}.
@@ -249,7 +268,7 @@ public class OutlineShape implements Comparable<OutlineShape> {
* @throws IndexOutOfBoundsException if position is out of range (position < 0 || position >= getOutlineNumber())
*/
public final Outline removeOutline(int position) throws IndexOutOfBoundsException {
- dirtyBits |= DIRTY_BOUNDS;
+ dirtyBits |= DIRTY_BOUNDS | DIRTY_TRIANGLES | DIRTY_VERTICES;
return outlines.remove(position);
}
@@ -278,6 +297,8 @@ public class OutlineShape implements Comparable<OutlineShape> {
if( 0 == ( dirtyBits & DIRTY_BOUNDS ) ) {
bbox.resize(lo.getBounds());
}
+ // vertices.add(v); // FIXME: can do and remove DIRTY_VERTICES ?
+ dirtyBits |= DIRTY_TRIANGLES | DIRTY_VERTICES;
}
/** Adds a vertex to the last open outline in the shape.
@@ -291,6 +312,7 @@ public class OutlineShape implements Comparable<OutlineShape> {
if( 0 == ( dirtyBits & DIRTY_BOUNDS ) ) {
bbox.resize(lo.getBounds());
}
+ dirtyBits |= DIRTY_TRIANGLES | DIRTY_VERTICES;
}
/** Add a 2D {@link Vertex} to the last outline by defining the coordniate attribute
@@ -338,7 +360,9 @@ public class OutlineShape implements Comparable<OutlineShape> {
* is equal to the first.</p>
*/
public void closeLastOutline() {
- getLastOutline().setClosed(true);
+ if( getLastOutline().setClosed(true) ) {
+ dirtyBits |= DIRTY_TRIANGLES | DIRTY_VERTICES;
+ }
}
/**
@@ -348,7 +372,8 @@ public class OutlineShape implements Comparable<OutlineShape> {
return outlineState;
}
- /** Ensure the outlines represent
+ /**
+ * Ensure the outlines represent
* the specified destinationType.
* and removes all overlaps in boundary triangles
* @param destinationType the target outline's vertices state. Currently only
@@ -376,6 +401,7 @@ public class OutlineShape implements Comparable<OutlineShape> {
outline.addVertex(index, vertexFactory.create(v1, 0, 3, false));
outline.addVertex(index+2, vertexFactory.create(v3, 0, 3, false));
+ dirtyBits |= DIRTY_VERTICES;
}
/** Check overlaps between curved triangles
@@ -480,10 +506,12 @@ public class OutlineShape implements Comparable<OutlineShape> {
i++;
vertexCount++;
outline.addVertex(i, v);
+ dirtyBits |= DIRTY_VERTICES;
}
}
if(vertexCount <= 0) {
outlines.remove(outline);
+ dirtyBits |= DIRTY_VERTICES;
cc--;
count--;
continue;
@@ -511,37 +539,90 @@ public class OutlineShape implements Comparable<OutlineShape> {
}
}
- /** @return the list of concatenated vertices associated with all
- * {@code Outline}s of this object
+ /**
+ * Return list of concatenated vertices associated with all
+ * {@code Outline}s of this object.
+ * <p>
+ * Vertices are cached until marked dirty.
+ * </p>
+ * FIXME: Add memory optimization, i.e. VBO layout
*/
public ArrayList<Vertex> getVertices() {
- ArrayList<Vertex> vertices = new ArrayList<Vertex>();
- for(int i=0; i<outlines.size(); i++) {
- vertices.addAll(outlines.get(i).getVertices());
+ if( 0 != ( DIRTY_VERTICES & dirtyBits ) ) {
+ vertices.clear();
+ for(int i=0; i<outlines.size(); i++) {
+ vertices.addAll(outlines.get(i).getVertices());
+ }
+ dirtyBits &= ~DIRTY_VERTICES;
}
return vertices;
}
+ private void triangulateImpl() {
+ if( 0 < outlines.size() ) {
+ sortOutlines();
+ generateVertexIds();
+
+ triangles.clear();
+ final Triangulator triangulator2d = Triangulation.create();
+ for(int index = 0; index<outlines.size(); index++) {
+ triangulator2d.addCurve(triangles, outlines.get(index));
+ }
+ triangulator2d.generate(triangles);
+ triangulator2d.reset();
+ }
+ dirtyBits &= ~DIRTY_TRIANGLES;
+ }
+
/**
* Triangulate the {@link OutlineShape} generating a list of triangles
+ * while {@link #transformOutlines(VerticesState)} beforehand w/
+ * {@link OutlineShape.VerticesState#QUADRATIC_NURBS}.
+ * <p>
+ * Triangles are cached until marked dirty.
+ * </p>
* @return an arraylist of triangles representing the filled region
* which is produced by the combination of the outlines
+ * FIXME: Add memory optimization, i.e. VBO layout
*/
- public ArrayList<Triangle> triangulate() {
- if(outlines.size() == 0){
- return null;
+ public ArrayList<Triangle> getTriangles() {
+ final boolean updated;
+ if( 0 != ( DIRTY_TRIANGLES & dirtyBits ) ) {
+ transformOutlines(OutlineShape.VerticesState.QUADRATIC_NURBS);
+ triangulateImpl();
+ updated = true;
+ } else {
+ updated = false;
}
- sortOutlines();
- generateVertexIds();
-
- Triangulator triangulator2d = Triangulation.create();
- for(int index = 0; index<outlines.size(); index++) {
- triangulator2d.addCurve(outlines.get(index));
+ if(Region.DEBUG_INSTANCE) {
+ System.err.println("OutlineShape.getTriangles().1: "+triangles.size()+", updated "+updated);
}
- ArrayList<Triangle> triangles = triangulator2d.generate();
- triangulator2d.reset();
+ return triangles;
+ }
+ /**
+ * Triangulate the {@link OutlineShape} generating a list of triangles,
+ * while {@link #transformOutlines(VerticesState)} beforehand.
+ * <p>
+ * Triangles are cached until marked dirty.
+ * </p>
+ * @return an arraylist of triangles representing the filled region
+ * which is produced by the combination of the outlines
+ * FIXME: Add memory optimization, i.e. VBO layout
+ */
+ public ArrayList<Triangle> getTriangles(VerticesState destinationType) {
+ final boolean updated;
+ if( 0 != ( DIRTY_TRIANGLES & dirtyBits ) ) {
+ transformOutlines(destinationType);
+ triangulateImpl();
+ updated = true;
+ } else {
+ updated = false;
+ }
+ if(Region.DEBUG_INSTANCE) {
+ System.err.println("OutlineShape.getTriangles().2: "+triangles.size()+", updated "+updated);
+ }
return triangles;
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java
index e36e37c26..2b6da2084 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/Region.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java
@@ -31,6 +31,7 @@ import java.util.ArrayList;
import java.util.List;
import jogamp.graph.curve.opengl.RegionFactory;
+import jogamp.graph.geom.plane.AffineTransform;
import jogamp.opengl.Debug;
import com.jogamp.graph.curve.opengl.GLRegion;
@@ -46,8 +47,7 @@ public abstract class Region {
/** Debug flag for region impl (graph.curve) */
public static final boolean DEBUG = Debug.debug("graph.curve");
-
- public static final boolean DEBUG_INSTANCE = false;
+ public static final boolean DEBUG_INSTANCE = Debug.debug("graph.curve.instance");
/** View based Anti-Aliasing, A Two pass region rendering, slower and more
* resource hungry (FBO), but AA is perfect. Otherwise the default fast one
@@ -65,7 +65,9 @@ public abstract class Region {
private boolean dirty = true;
protected int numVertices = 0;
protected final AABBox box = new AABBox();
+ /** FIXME: Think about a rendering storage optimization (VBO ... )! */
protected ArrayList<Triangle> triangles = new ArrayList<Triangle>();
+ /** FIXME: Think about a rendering storage optimization (VBO ... )! */
protected ArrayList<Vertex> vertices = new ArrayList<Vertex>();
public static boolean isVBAA(int renderModes) {
@@ -99,7 +101,7 @@ public abstract class Region {
*/
public static Region create(OutlineShape outlineShape, int renderModes) {
final Region region = RegionFactory.create(renderModes);
- region.addOutlineShape(outlineShape);
+ region.addOutlineShape(outlineShape, null);
return region;
}
@@ -136,27 +138,32 @@ public abstract class Region {
return numVertices;
}
- /** Adds a {@link Triangle} object to the Region This triangle will be bound
- * to OGL objects on the next call to {@code update}
- *
- * @param tri
- * a triangle object
- *
- * @see update(GL2ES2) */
- public void addTriangle(Triangle tri) {
- triangles.add(tri);
- setDirty(true);
- }
-
/** Adds a list of {@link Triangle} objects to the Region These triangles are
* to be binded to OGL objects on the next call to {@code update}
*
* @param tris
* a list of triangle objects
+ * @param idxOffset TODO
*
* @see update(GL2ES2) */
- public void addTriangles(List<Triangle> tris) {
- triangles.addAll(tris);
+ public void addTriangles(List<Triangle> tris, AffineTransform t, int idxOffset) {
+ if( true && null != t ) {
+ for(int i=0; i<tris.size(); i++) {
+ final Triangle t2 = tris.get(i).transform(t);
+ t2.addVertexIndicesOffset(idxOffset);
+ triangles.add( t2 );
+ }
+ } else {
+ for(int i=0; i<tris.size(); i++) {
+ final Triangle t2 = new Triangle( tris.get(i) );
+ t2.addVertexIndicesOffset(idxOffset);
+ triangles.add( t2 );
+ }
+ // triangles.addAll(tris);
+ }
+ if(DEBUG_INSTANCE) {
+ System.err.println("Region.addTriangles(): tris: "+triangles.size()+", verts "+vertices.size());
+ }
setDirty(true);
}
@@ -167,9 +174,14 @@ public abstract class Region {
* a vertex objects
*
* @see update(GL2ES2) */
- public void addVertex(Vertex vert) {
- vertices.add(vert);
+ public void addVertex(Vertex vert, AffineTransform t) {
+ final Vertex svert = null != t ? t.transform(vert, null) : vert;
+ vertices.add(svert);
numVertices++;
+ assert( vertices.size() == numVertices );
+ if(DEBUG_INSTANCE) {
+ System.err.println("Region.addVertex(): tris: "+triangles.size()+", verts "+vertices.size());
+ }
setDirty(true);
}
@@ -183,29 +195,51 @@ public abstract class Region {
public void addVertices(List<Vertex> verts) {
vertices.addAll(verts);
numVertices = vertices.size();
+ if(DEBUG_INSTANCE) {
+ System.err.println("Region.addVertices(): tris: "+triangles.size()+", verts "+vertices.size());
+ }
setDirty(true);
}
- public void addOutlineShape(OutlineShape shape) {
- shape.transformOutlines(OutlineShape.VerticesState.QUADRATIC_NURBS);
- List<Triangle> tris = shape.triangulate();
+ public void addOutlineShape(OutlineShape shape, AffineTransform t) {
+ final List<Triangle> tris = shape.getTriangles(OutlineShape.VerticesState.QUADRATIC_NURBS);
if(null != tris) {
- triangles.addAll(tris);
+ if( false && null != t ) {
+ for(int i=0; i<tris.size(); i++) {
+ triangles.add( tris.get(i).transform(t) );
+ }
+ } else {
+ triangles.addAll(tris);
+ }
+ // final List<Vertex> verts = shape.getVertices();
+ // vertices.addAll(verts);
for (int j = 0; j < shape.outlines.size(); j++) {
final ArrayList<Vertex> sovs = shape.outlines.get(j).getVertices();
for (int k = 0; k < sovs.size(); k++) {
- final Vertex v = sovs.get(k);
+ final Vertex v;
+ if( null != t ) {
+ v = t.transform(sovs.get(k), null);
+ } else {
+ v = sovs.get(k);
+ }
v.setId(numVertices++);
vertices.add(v);
}
}
+ // numVertices = vertices.size();
+ }
+ if(DEBUG_INSTANCE) {
+ System.err.println("Region.addOutlineShape(): tris: "+triangles.size()+", verts "+vertices.size());
}
setDirty(true);
}
public void addOutlineShapes(List<OutlineShape> shapes) {
for (int i = 0; i < shapes.size(); i++) {
- addOutlineShape(shapes.get(i));
+ addOutlineShape(shapes.get(i), null);
+ }
+ if(DEBUG_INSTANCE) {
+ System.err.println("Region.addOutlineShapes(): tris: "+triangles.size()+", verts "+vertices.size());
}
setDirty(true);
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderUtil.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderUtil.java
new file mode 100644
index 000000000..cef589f4f
--- /dev/null
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderUtil.java
@@ -0,0 +1,332 @@
+/**
+ * Copyright 2014 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.graph.curve.opengl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GLException;
+
+import jogamp.graph.curve.opengl.RegionFactory;
+import jogamp.graph.geom.plane.AffineTransform;
+
+import com.jogamp.graph.curve.OutlineShape;
+import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.font.Font;
+import com.jogamp.graph.font.Font.Glyph;
+import com.jogamp.graph.geom.Triangle;
+import com.jogamp.graph.geom.Vertex;
+import com.jogamp.graph.geom.Vertex.Factory;
+
+/**
+ *
+ * FIXME: Add VBO Vertex Factory for drawString3D !
+ *
+ */
+public class TextRenderUtil {
+
+ public final Renderer renderer;
+
+ public TextRenderUtil(final Renderer renderer) {
+ this.renderer = renderer;
+ }
+
+ /**
+ * Generate a Region to represent this Object.
+ * <p>
+ * Each glyph is cached and reused.
+ * </p>
+ *
+ * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#VBAA_RENDERING_BIT}
+ * @param vertexFactory vertex impl factory {@link Factory}
+ * @param font the target {@link Font}
+ * @param str string text
+ * @param pixelSize
+ */
+ public static GLRegion createRegion(final int renderModes, final Factory<? extends Vertex> vertexFactory,
+ final Font font, final CharSequence str, final int pixelSize) {
+ final int charCount = str.length();
+
+ final GLRegion region = RegionFactory.create(renderModes);
+ // region.setFlipped(true);
+ final Font.Metrics metrics = font.getMetrics();
+
+ final float lineGap = metrics.getLineGap(pixelSize) ;
+ final float ascent = metrics.getAscent(pixelSize) ;
+ final float descent = metrics.getDescent(pixelSize) ;
+ final float advanceY = lineGap - descent + ascent;
+ final float scale = metrics.getScale(pixelSize);
+ final AffineTransform transform = new AffineTransform(vertexFactory);
+ final AffineTransform t = new AffineTransform(vertexFactory);
+
+ float y = 0;
+ float advanceTotal = 0;
+ int numVertices = region.getNumVertices();
+
+ for(int i=0; i< charCount; i++) {
+ final char character = str.charAt(i);
+ if( '\n' == character ) {
+ y += advanceY;
+ advanceTotal = 0;
+ } else if (character == ' ') {
+ advanceTotal += font.getAdvanceWidth(Glyph.ID_SPACE, pixelSize);
+ } else {
+ if(Region.DEBUG_INSTANCE) {
+ System.err.println("XXXXXXXXXXXXXXx char: "+character+", scale: "+scale+"; translate: "+advanceTotal+", "+y);
+ }
+ t.setTransform(transform); // reset transform
+ t.translate(advanceTotal, y);
+ t.scale(scale, scale);
+
+ final Font.Glyph glyph = font.getGlyph(character);
+ final OutlineShape glyphShape = glyph.getShape();
+ if( null == glyphShape || glyphShape.getVertices().size() < 3 ) {
+ continue;
+ }
+ // glyphShape.closeLastOutline();
+
+ if( false ) {
+ region.addOutlineShape(glyphShape, t);
+ } else {
+ final ArrayList<Triangle> trisIn = glyphShape.getTriangles();
+ region.addTriangles(trisIn, t, numVertices);
+
+ final ArrayList<Vertex> gVertices = glyphShape.getVertices();
+ for(int j=0; j<gVertices.size(); j++) {
+ final Vertex vert = gVertices.get(j);
+ final Vertex svert = t.transform(vert, null);
+ svert.setId(numVertices++);
+ if(Region.DEBUG_INSTANCE) {
+ System.err.println("IN: "+vert);
+ System.err.println("EX: "+svert);
+ }
+ region.addVertex(svert, null);
+ }
+ }
+ assert( numVertices == region.getNumVertices() );
+
+ advanceTotal += glyph.getAdvance(pixelSize, true);
+ }
+ }
+ return region;
+ }
+
+ private static GLRegion createRegion2(final int renderModes, final Factory<? extends Vertex> vertexFactory,
+ final Font font, final CharSequence str, final int pixelSize) {
+ final List<OutlineShape> shapesIn = font.getOutlineShapes(null, str, pixelSize, vertexFactory);
+ final ArrayList<OutlineShape> shapesOut = new ArrayList<OutlineShape>();
+ final int numGlyps = shapesIn.size();
+ for (int index=0;index<numGlyps;index++){
+ if(shapesIn.get(index) == null){
+ continue;
+ }
+ final OutlineShape glyphShape = shapesIn.get(index);
+
+ if(glyphShape.getVertices().size() < 3) {
+ continue;
+ }
+ shapesOut.add(glyphShape);
+ }
+
+ final GLRegion region = RegionFactory.create(renderModes);
+ // region.setFlipped(true);
+ int numVertices = region.getNumVertices();
+
+ for(int i=0; i< shapesOut.size(); i++) {
+ final OutlineShape shape = shapesOut.get(i);
+ ArrayList<Triangle> gtris = shape.getTriangles();
+ region.addTriangles(gtris, null, 0);
+
+ final ArrayList<Vertex> gVertices = shape.getVertices();
+ for(int j=0; j<gVertices.size(); j++) {
+ final Vertex gVert = gVertices.get(j);
+ gVert.setId(numVertices++);
+ region.addVertex(gVert, null);
+ }
+ }
+ return region;
+ }
+
+
+ /**
+ * Render the String in 3D space wrt to the font provided at the position provided
+ * the outlines will be generated, if not yet generated
+ * @param gl the current GL state
+ * @param font {@link Font} to be used
+ * @param str text to be rendered
+ * @param pixelSize font size
+ * @param texWidth desired texture width for multipass-rendering.
+ * The actual used texture-width is written back when mp rendering is enabled, otherwise the store is untouched.
+ * @throws Exception if TextRenderer not initialized
+ */
+ public void drawString3D(final GL2ES2 gl,
+ final Font font, final CharSequence str, final int pixelSize, final int[/*1*/] texSize) {
+ if(!renderer.isInitialized()){
+ throw new GLException("TextRendererImpl01: not initialized!");
+ }
+ final RenderState rs = renderer.getRenderState();
+ GLRegion region = getCachedRegion(font, str, pixelSize);
+ if(null == region) {
+ region = createRegion(renderer.getRenderModes(), rs.getVertexFactory(), font, str, pixelSize);
+ addCachedRegion(gl, font, str, pixelSize, region);
+ }
+ region.draw(gl, rs, renderer.getWidth(), renderer.getHeight(), texSize);
+ }
+
+ /**
+ * Render the String in 3D space wrt to the font provided at the position provided
+ * the outlines will be generated, if not yet generated
+ * @param gl the current GL state
+ * @param font {@link Font} to be used
+ * @param str text to be rendered
+ * @param fontSize font size
+ * @param texWidth desired texture width for multipass-rendering.
+ * The actual used texture-width is written back when mp rendering is enabled, otherwise the store is untouched.
+ * @throws Exception if TextRenderer not initialized
+ */
+ public static void drawString3D(final Renderer renderer, final GL2ES2 gl,
+ final Font font, final CharSequence str, final int fontSize, final int[/*1*/] texSize) {
+ if(!renderer.isInitialized()){
+ throw new GLException("TextRendererImpl01: not initialized!");
+ }
+ final RenderState rs = renderer.getRenderState();
+ GLRegion region = createRegion(renderer.getRenderModes(), rs.getVertexFactory(), font, str, fontSize);
+ region.draw(gl, rs, renderer.getWidth(), renderer.getHeight(), texSize);
+ }
+
+ /** FIXME
+ public void flushCache(GL2ES2 gl) {
+ Iterator<GlyphString> iterator = stringCacheMap.values().iterator();
+ while(iterator.hasNext()){
+ GlyphString glyphString = iterator.next();
+ glyphString.destroy(gl, rs);
+ }
+ stringCacheMap.clear();
+ stringCacheArray.clear();
+ } */
+
+ public void destroy(GL2ES2 gl) {
+ // fluchCache(gl) already called
+ final Iterator<GLRegion> iterator = stringCacheMap.values().iterator();
+ while(iterator.hasNext()){
+ final GLRegion region = iterator.next();
+ region.destroy(gl, renderer.getRenderState());
+ }
+ stringCacheMap.clear();
+ stringCacheArray.clear();
+ }
+
+ /**
+ * <p>Sets the cache limit for reusing GlyphString's and their Region.
+ * Default is {@link #DEFAULT_CACHE_LIMIT}, -1 unlimited, 0 turns cache off, >0 limited </p>
+ *
+ * <p>The cache will be validate when the next string rendering happens.</p>
+ *
+ * @param newLimit new cache size
+ *
+ * @see #DEFAULT_CACHE_LIMIT
+ */
+ public final void setCacheLimit(int newLimit ) { stringCacheLimit = newLimit; }
+
+ /**
+ * Sets the cache limit, see {@link #setCacheLimit(int)} and validates the cache.
+ *
+ * @see #setCacheLimit(int)
+ *
+ * @param gl current GL used to remove cached objects if required
+ * @param newLimit new cache size
+ */
+ public final void setCacheLimit(GL2ES2 gl, int newLimit ) { stringCacheLimit = newLimit; validateCache(gl, 0); }
+
+ /**
+ * @return the current cache limit
+ */
+ public final int getCacheLimit() { return stringCacheLimit; }
+
+ /**
+ * @return the current utilized cache size, <= {@link #getCacheLimit()}
+ */
+ public final int getCacheSize() { return stringCacheArray.size(); }
+
+ protected final void validateCache(GL2ES2 gl, int space) {
+ if ( getCacheLimit() > 0 ) {
+ while ( getCacheSize() + space > getCacheLimit() ) {
+ removeCachedRegion(gl, 0);
+ }
+ }
+ }
+
+ protected final GLRegion getCachedRegion(Font font, CharSequence str, int fontSize) {
+ return stringCacheMap.get(getKey(font, str, fontSize));
+ }
+
+ protected final void addCachedRegion(GL2ES2 gl, Font font, CharSequence str, int fontSize, GLRegion glyphString) {
+ if ( 0 != getCacheLimit() ) {
+ final String key = getKey(font, str, fontSize);
+ final GLRegion oldRegion = stringCacheMap.put(key, glyphString);
+ if ( null == oldRegion ) {
+ // new entry ..
+ validateCache(gl, 1);
+ stringCacheArray.add(stringCacheArray.size(), key);
+ } /// else overwrite is nop ..
+ }
+ }
+
+ protected final void removeCachedRegion(GL2ES2 gl, Font font, CharSequence str, int fontSize) {
+ final String key = getKey(font, str, fontSize);
+ GLRegion region = stringCacheMap.remove(key);
+ if(null != region) {
+ region.destroy(gl, renderer.getRenderState());
+ }
+ stringCacheArray.remove(key);
+ }
+
+ protected final void removeCachedRegion(GL2ES2 gl, int idx) {
+ final String key = stringCacheArray.remove(idx);
+ final GLRegion region = stringCacheMap.remove(key);
+ if(null != region) {
+ region.destroy(gl, renderer.getRenderState());
+ }
+ }
+
+ protected final String getKey(Font font, CharSequence str, int fontSize) {
+ final StringBuilder sb = new StringBuilder();
+ return font.getName(sb, Font.NAME_UNIQUNAME)
+ .append(".").append(str.hashCode()).append(".").append(fontSize).toString();
+ }
+
+ /** Default cache limit, see {@link #setCacheLimit(int)} */
+ public static final int DEFAULT_CACHE_LIMIT = 256;
+
+ private final HashMap<String, GLRegion> stringCacheMap = new HashMap<String, GLRegion>(DEFAULT_CACHE_LIMIT);
+ private final ArrayList<String> stringCacheArray = new ArrayList<String>(DEFAULT_CACHE_LIMIT);
+ private int stringCacheLimit = DEFAULT_CACHE_LIMIT;
+} \ No newline at end of file
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java
deleted file mode 100644
index 44007ca79..000000000
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/**
- * Copyright 2010 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.graph.curve.opengl;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-
-import javax.media.opengl.GL2ES2;
-
-import jogamp.graph.curve.text.GlyphString;
-
-import com.jogamp.graph.curve.OutlineShape;
-import com.jogamp.graph.font.Font;
-import com.jogamp.graph.geom.Vertex.Factory;
-
-/**
- * @deprecated use {@link com.jogamp.graph.font.Font#getOutlineShapes(java.util.List, CharSequence, float, Factory)},
- * {@link com.jogamp.graph.curve.Region#create(OutlineShape, int)}
- * and a {@link com.jogamp.graph.curve.opengl.RegionRenderer}.
- */
-public abstract class TextRenderer extends Renderer {
- /**
- * Create a Hardware accelerated Text Renderer.
- * @param rs the used {@link RenderState}
- * @param renderModes either {@link com.jogamp.graph.curve.opengl.GLRegion#SINGLE_PASS} or {@link com.jogamp.graph.curve.Region#VBAA_RENDERING_BIT}
- */
- public static TextRenderer create(RenderState rs, int renderModes) {
- return new jogamp.graph.curve.opengl.TextRendererImpl01(rs, renderModes);
- }
-
- protected TextRenderer(RenderState rs, int type) {
- super(rs, type);
- }
-
-
- /** Render the String in 3D space wrt to the font provided at the position provided
- * the outlines will be generated, if not yet generated
- * @param gl the current GL state
- * @param font {@link Font} to be used
- * @param str text to be rendered
- * @param fontSize font size
- * @param texWidth desired texture width for multipass-rendering.
- * The actual used texture-width is written back when mp rendering is enabled, otherwise the store is untouched.
- * @throws Exception if TextRenderer not initialized
- */
- public abstract void drawString3D(GL2ES2 gl, Font font,
- String str, int fontSize, int[/*1*/] texSize);
-
- /**Create the resulting {@link GlyphString} that represents
- * the String wrt to the font.
- * @param font {@link Font} to be used
- * @param size font size
- * @param str {@link String} to be created
- * @return the resulting GlyphString inclusive the generated region
- */
- public GlyphString createString(GL2ES2 gl, Font font, int size, String str) {
- if(DEBUG_INSTANCE) {
- System.err.println("createString: "+getCacheSize()+"/"+getCacheLimit()+" - "+Font.NAME_UNIQUNAME + " - " + str + " - " + size);
- }
- final GlyphString glyphString = GlyphString.createString(null, rs.getVertexFactory(), font, size, str);
- glyphString.createRegion(gl, renderModes);
- return glyphString;
- }
-
- /** FIXME
- public void flushCache(GL2ES2 gl) {
- Iterator<GlyphString> iterator = stringCacheMap.values().iterator();
- while(iterator.hasNext()){
- GlyphString glyphString = iterator.next();
- glyphString.destroy(gl, rs);
- }
- stringCacheMap.clear();
- stringCacheArray.clear();
- } */
-
- @Override
- protected void destroyImpl(GL2ES2 gl) {
- // fluchCache(gl) already called
- Iterator<GlyphString> iterator = stringCacheMap.values().iterator();
- while(iterator.hasNext()){
- GlyphString glyphString = iterator.next();
- glyphString.destroy(gl, rs);
- }
- stringCacheMap.clear();
- stringCacheArray.clear();
- }
-
- /**
- * <p>Sets the cache limit for reusing GlyphString's and their Region.
- * Default is {@link #DEFAULT_CACHE_LIMIT}, -1 unlimited, 0 turns cache off, >0 limited </p>
- *
- * <p>The cache will be validate when the next string rendering happens.</p>
- *
- * @param newLimit new cache size
- *
- * @see #DEFAULT_CACHE_LIMIT
- */
- public final void setCacheLimit(int newLimit ) { stringCacheLimit = newLimit; }
-
- /**
- * Sets the cache limit, see {@link #setCacheLimit(int)} and validates the cache.
- *
- * @see #setCacheLimit(int)
- *
- * @param gl current GL used to remove cached objects if required
- * @param newLimit new cache size
- */
- public final void setCacheLimit(GL2ES2 gl, int newLimit ) { stringCacheLimit = newLimit; validateCache(gl, 0); }
-
- /**
- * @return the current cache limit
- */
- public final int getCacheLimit() { return stringCacheLimit; }
-
- /**
- * @return the current utilized cache size, <= {@link #getCacheLimit()}
- */
- public final int getCacheSize() { return stringCacheArray.size(); }
-
- protected final void validateCache(GL2ES2 gl, int space) {
- if ( getCacheLimit() > 0 ) {
- while ( getCacheSize() + space > getCacheLimit() ) {
- removeCachedGlyphString(gl, 0);
- }
- }
- }
-
- protected final GlyphString getCachedGlyphString(Font font, String str, int fontSize) {
- return stringCacheMap.get(getKey(font, str, fontSize));
- }
-
- protected final void addCachedGlyphString(GL2ES2 gl, Font font, String str, int fontSize, GlyphString glyphString) {
- if ( 0 != getCacheLimit() ) {
- final String key = getKey(font, str, fontSize);
- GlyphString oldGlyphString = stringCacheMap.put(key, glyphString);
- if ( null == oldGlyphString ) {
- // new entry ..
- validateCache(gl, 1);
- stringCacheArray.add(stringCacheArray.size(), key);
- } /// else overwrite is nop ..
- }
- }
-
- protected final void removeCachedGlyphString(GL2ES2 gl, Font font, String str, int fontSize) {
- final String key = getKey(font, str, fontSize);
- GlyphString glyphString = stringCacheMap.remove(key);
- if(null != glyphString) {
- glyphString.destroy(gl, rs);
- }
- stringCacheArray.remove(key);
- }
-
- protected final void removeCachedGlyphString(GL2ES2 gl, int idx) {
- final String key = stringCacheArray.remove(idx);
- final GlyphString glyphString = stringCacheMap.remove(key);
- if(null != glyphString) {
- glyphString.destroy(gl, rs);
- }
- }
-
- protected final String getKey(Font font, String str, int fontSize) {
- final StringBuilder sb = new StringBuilder();
- return font.getName(sb, Font.NAME_UNIQUNAME)
- .append(".").append(str.hashCode()).append(".").append(fontSize).toString();
- }
-
- /** Default cache limit, see {@link #setCacheLimit(int)} */
- public static final int DEFAULT_CACHE_LIMIT = 256;
-
- private final HashMap<String, GlyphString> stringCacheMap = new HashMap<String, GlyphString>(DEFAULT_CACHE_LIMIT);
- private final ArrayList<String> stringCacheArray = new ArrayList<String>(DEFAULT_CACHE_LIMIT);
- private int stringCacheLimit = DEFAULT_CACHE_LIMIT;
-} \ No newline at end of file
diff --git a/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java b/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java
index 4e8c400e0..39e84171b 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/tess/Triangulator.java
@@ -28,7 +28,7 @@
package com.jogamp.graph.curve.tess;
-import java.util.ArrayList;
+import java.util.List;
import com.jogamp.graph.geom.Outline;
import com.jogamp.graph.geom.Triangle;
@@ -49,18 +49,19 @@ import com.jogamp.graph.geom.Triangle;
*/
public interface Triangulator {
- /** Add a curve to the list of Outlines
+ /**
+ * Add a curve to the list of Outlines
* describing the shape
+ * @param sink list where the generated triangles will be added
* @param outline a bounding {@link Outline}
*/
- public void addCurve(Outline outline);
+ public void addCurve(List<Triangle> sink, Outline outline);
/** Generate the triangulation of the provided
* List of {@link Outline}s
- * @return an arraylist of {@link Triangle}s resembling the
- * final shape.
+ * @param sink list where the generated triangles will be added
*/
- public ArrayList<Triangle> generate();
+ public void generate(List<Triangle> sink);
/** Reset the triangulation to initial state
* Clearing cached data
diff --git a/src/jogl/classes/com/jogamp/graph/font/Font.java b/src/jogl/classes/com/jogamp/graph/font/Font.java
index 6c0041de9..1e0572037 100644
--- a/src/jogl/classes/com/jogamp/graph/font/Font.java
+++ b/src/jogl/classes/com/jogamp/graph/font/Font.java
@@ -91,6 +91,7 @@ public interface Font {
public float getScale(float pixelSize);
public AABBox getBBox(float pixelSize);
public float getAdvance(float pixelSize, boolean useFrationalMetrics);
+ public OutlineShape getShape();
public int hashCode();
}
@@ -117,13 +118,7 @@ public interface Font {
public boolean isPrintableChar( char c );
/**
- * @param glyph source of the created OutlineShape
- * @param vertexFactory factory for vertices
- * @return OutlineShape of the glyph
- */
- public OutlineShape getOutlineShape(Glyph glyph, Factory<? extends Vertex> vertexFactory);
-
- /**
+ * @deprecated Remove altogether - use {@link #getOutlineShape(Glyph, Factory)
* @param shapes optional storage of OutlineShapes passed by user, new shapes are appended
* @param string source of the created OutlineShapes
* @param pixelSize
diff --git a/src/jogl/classes/com/jogamp/graph/geom/Outline.java b/src/jogl/classes/com/jogamp/graph/geom/Outline.java
index 77a318078..26eba2741 100644
--- a/src/jogl/classes/com/jogamp/graph/geom/Outline.java
+++ b/src/jogl/classes/com/jogamp/graph/geom/Outline.java
@@ -156,17 +156,20 @@ public class Outline implements Cloneable, Comparable<Outline> {
* equal to the first vertex. If not Equal adds a
* vertex at the end to the list.
* @param closed
+ * @return true if closing performed, otherwise false for NOP
*/
- public final void setClosed(boolean closed) {
+ public final boolean setClosed(boolean closed) {
this.closed = closed;
if( closed && !isEmpty() ) {
- Vertex first = vertices.get(0);
- Vertex last = getLastVertex();
+ final Vertex first = vertices.get(0);
+ final Vertex last = getLastVertex();
if(!VectorUtil.checkEquality(first.getCoord(), last.getCoord())){
Vertex v = first.clone();
vertices.add(v);
+ return true;
}
}
+ return false;
}
/** Compare two outlines with Bounding Box area
diff --git a/src/jogl/classes/com/jogamp/graph/geom/opengl/SVertex.java b/src/jogl/classes/com/jogamp/graph/geom/SVertex.java
index b27604a44..99f10a694 100644
--- a/src/jogl/classes/com/jogamp/graph/geom/opengl/SVertex.java
+++ b/src/jogl/classes/com/jogamp/graph/geom/SVertex.java
@@ -25,9 +25,8 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of JogAmp Community.
*/
-package com.jogamp.graph.geom.opengl;
+package com.jogamp.graph.geom;
-import com.jogamp.graph.geom.Vertex;
import com.jogamp.opengl.math.VectorUtil;
/** A Simple Vertex Implementation. Where the coordinates, and other attributes are
@@ -35,10 +34,10 @@ import com.jogamp.opengl.math.VectorUtil;
*
*/
public class SVertex implements Vertex {
- private int id = Integer.MAX_VALUE;
- protected float[] coord = new float[3];
+ private int id;
+ protected final float[] coord = new float[3];
protected boolean onCurve;
- private float[] texCoord = new float[2];
+ private final float[] texCoord = new float[2];
static final Factory factory = new Factory();
@@ -50,8 +49,17 @@ public class SVertex implements Vertex {
return new SVertex();
}
+ public SVertex create(final Vertex src) {
+ return new SVertex(src);
+ }
+
+ @Override
+ public SVertex create(final int id, final boolean onCurve, final float[] texCoordsBuffer) {
+ return new SVertex(id, onCurve, texCoordsBuffer);
+ }
+
@Override
- public SVertex create(float x, float y, float z, boolean onCurve) {
+ public SVertex create(final float x, final float y, final float z, final boolean onCurve) {
return new SVertex(x, y, z, onCurve);
}
@@ -62,30 +70,46 @@ public class SVertex implements Vertex {
}
public SVertex() {
+ this.id = Integer.MAX_VALUE;
+ }
+
+ public SVertex(final Vertex src) {
+ this.id = src.getId();
+ System.arraycopy(src.getCoord(), 0, coord, 0, 3);
+ setOnCurve(src.isOnCurve());
+ System.arraycopy(src.getTexCoord(), 0, texCoord, 0, 2);
}
- public SVertex(float x, float y, float z, boolean onCurve) {
+ public SVertex(final int id, final boolean onCurve, final float[] texCoordsBuffer) {
+ this.id = id;
+ this.onCurve = onCurve;
+ System.arraycopy(texCoordsBuffer, 0, texCoord, 0, 2);
+ }
+
+ public SVertex(final float x, final float y, final float z, final boolean onCurve) {
+ this.id = Integer.MAX_VALUE;
setCoord(x, y, z);
setOnCurve(onCurve);
}
- public SVertex(float[] coordsBuffer, int offset, int length, boolean onCurve) {
+ public SVertex(final float[] coordsBuffer, final int offset, final int length, final boolean onCurve) {
+ this.id = Integer.MAX_VALUE;
setCoord(coordsBuffer, offset, length);
setOnCurve(onCurve);
}
- public SVertex(float[] coordsBuffer, int offset, int length,
- float[] texCoordsBuffer, int offsetTC, int lengthTC, boolean onCurve) {
- setCoord(coordsBuffer, offset, length);
- setTexCoord(texCoordsBuffer, offsetTC, lengthTC);
+ public SVertex(float[] coordsBuffer, float[] texCoordsBuffer, boolean onCurve) {
+ this.id = Integer.MAX_VALUE;
+ System.arraycopy(coordsBuffer, 0, coord, 0, 3);
+ System.arraycopy(texCoordsBuffer, 0, texCoord, 0, 2);
setOnCurve(onCurve);
}
@Override
public final void setCoord(float x, float y, float z) {
- this.coord[0] = x;
- this.coord[1] = y;
- this.coord[2] = z;
+ coord[0] = x;
+ coord[1] = y;
+ coord[2] = z;
}
@Override
@@ -175,8 +199,8 @@ public class SVertex implements Vertex {
@Override
public final void setTexCoord(float s, float t) {
- this.texCoord[0] = s;
- this.texCoord[1] = t;
+ texCoord[0] = s;
+ texCoord[1] = t;
}
@Override
@@ -185,11 +209,11 @@ public class SVertex implements Vertex {
}
/**
- * @return deep clone of this Vertex, but keeping the id blank
+ * @return deep clone of this Vertex elements
*/
@Override
public SVertex clone(){
- return new SVertex(this.coord, 0, 3, this.texCoord, 0, 2, this.onCurve);
+ return new SVertex(this.coord, this.texCoord, this.onCurve);
}
@Override
diff --git a/src/jogl/classes/com/jogamp/graph/geom/Triangle.java b/src/jogl/classes/com/jogamp/graph/geom/Triangle.java
index a01cd834f..6de99c48b 100644
--- a/src/jogl/classes/com/jogamp/graph/geom/Triangle.java
+++ b/src/jogl/classes/com/jogamp/graph/geom/Triangle.java
@@ -27,14 +27,52 @@
*/
package com.jogamp.graph.geom;
+import com.jogamp.graph.curve.Region;
+
+import jogamp.graph.geom.plane.AffineTransform;
+
public class Triangle {
- private int id = Integer.MAX_VALUE;
- final private Vertex[] vertices;
- private boolean[] boundaryEdges = new boolean[3];
+ private final Vertex[] vertices = new Vertex[3];
+ private final boolean[] boundaryEdges = new boolean[3];
private boolean[] boundaryVertices = null;
+ private int id;
+
+ public Triangle(Vertex v1, Vertex v2, Vertex v3) {
+ id = Integer.MAX_VALUE;
+ vertices[0] = v1;
+ vertices[1] = v2;
+ vertices[2] = v3;
+ }
+
+ public Triangle(Triangle src) {
+ id = src.id;
+ vertices[0] = src.vertices[0].clone();
+ vertices[1] = src.vertices[1].clone();
+ vertices[2] = src.vertices[2].clone();
+ System.arraycopy(src.boundaryEdges, 0, boundaryEdges, 0, 3);
+ boundaryVertices = src.boundaryVertices;
+ }
+
+ private Triangle(final int id, final boolean[] boundaryEdges, final boolean[] boundaryVertices){
+ this.id = id;
+ System.arraycopy(boundaryEdges, 0, this.boundaryEdges, 0, 3);
+ this.boundaryVertices = boundaryVertices;
+ /**
+ if( null != boundaryVertices ) {
+ this.boundaryVertices = new boolean[3];
+ System.arraycopy(boundaryVertices, 0, this.boundaryVertices, 0, 3);
+ } */
+ }
- public Triangle(Vertex ... v123){
- vertices = v123;
+ /**
+ * Returns a transformed a clone of this instance using the given AffineTransform.
+ */
+ public Triangle transform(AffineTransform t) {
+ final Triangle tri = new Triangle(id, boundaryEdges, boundaryVertices);
+ tri.vertices[0] = t.transform(vertices[0], null);
+ tri.vertices[1] = t.transform(vertices[1], null);
+ tri.vertices[2] = t.transform(vertices[2], null);
+ return tri;
}
public int getId() {
@@ -45,6 +83,21 @@ public class Triangle {
this.id = id;
}
+ public void addVertexIndicesOffset(int offset) {
+ if( 0 < offset ) {
+ final int i0 = vertices[0].getId();
+ if( Integer.MAX_VALUE-offset > i0 ) { // Integer.MAX_VALUE != i0 // FIXME: renderer uses SHORT!
+ if(Region.DEBUG_INSTANCE) {
+ System.err.println("Triangle.addVertexIndicesOffset: "+i0+" + "+offset+" -> "+(i0+offset));
+ }
+ vertices[0].setId(i0+offset);
+ vertices[1].setId(vertices[1].getId()+offset);
+ vertices[2].setId(vertices[2].getId()+offset);
+ }
+ }
+ }
+
+ /** Returns array of 3 vertices, denominating the triangle. */
public Vertex[] getVertices() {
return vertices;
}
@@ -57,10 +110,6 @@ public class Triangle {
return boundaryVertices[0] || boundaryVertices[1] || boundaryVertices[2];
}
- public void setEdgesBoundary(boolean[] boundary) {
- this.boundaryEdges = boundary;
- }
-
public boolean[] getEdgeBoundary() {
return boundaryEdges;
}
diff --git a/src/jogl/classes/com/jogamp/graph/geom/Vertex.java b/src/jogl/classes/com/jogamp/graph/geom/Vertex.java
index 994253f71..fc9590ae7 100644
--- a/src/jogl/classes/com/jogamp/graph/geom/Vertex.java
+++ b/src/jogl/classes/com/jogamp/graph/geom/Vertex.java
@@ -37,6 +37,10 @@ public interface Vertex extends Vert3fImmutable, Cloneable {
public static interface Factory <T extends Vertex> {
T create();
+ T create(Vertex src);
+
+ T create(int id, boolean onCurve, float[] texCoordsBuffer);
+
T create(float x, float y, float z, boolean onCurve);
T create(float[] coordsBuffer, int offset, int length, boolean onCurve);
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java b/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
deleted file mode 100644
index c3c7e0cac..000000000
--- a/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * Copyright 2010 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 jogamp.graph.curve.opengl;
-
-import javax.media.opengl.GL2ES2;
-import javax.media.opengl.GLException;
-
-import jogamp.graph.curve.opengl.shader.AttributeNames;
-import jogamp.graph.curve.text.GlyphString;
-
-import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.curve.opengl.TextRenderer;
-import com.jogamp.graph.font.Font;
-import com.jogamp.opengl.GLExtensions;
-import com.jogamp.opengl.util.glsl.ShaderCode;
-import com.jogamp.opengl.util.glsl.ShaderProgram;
-import com.jogamp.opengl.util.glsl.ShaderState;
-
-public class TextRendererImpl01 extends TextRenderer {
- public TextRendererImpl01(RenderState rs, int type) {
- super(rs, type);
- }
-
- @Override
- protected boolean initShaderProgram(GL2ES2 gl){
- final ShaderState st = rs.getShaderState();
-
- final ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, TextRendererImpl01.class, "shader",
- "shader/bin", getVertexShaderName(), true);
- final ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, TextRendererImpl01.class, "shader",
- "shader/bin", getFragmentShaderName(), true);
- rsVp.defaultShaderCustomization(gl, true, true);
- // rsFp.defaultShaderCustomization(gl, true, true);
- int pos = rsFp.addGLSLVersion(gl);
- if( gl.isGLES() ) {
- pos = rsFp.insertShaderSource(0, pos, ShaderCode.createExtensionDirective(GLExtensions.OES_standard_derivatives, ShaderCode.ENABLE));
- }
- final String rsFpDefPrecision = getFragmentShaderPrecision(gl);
- if( null != rsFpDefPrecision ) {
- rsFp.insertShaderSource(0, pos, rsFpDefPrecision);
- }
-
- final ShaderProgram sp = new ShaderProgram();
- sp.add(rsVp);
- sp.add(rsFp);
-
- if( !sp.init(gl) ) {
- throw new GLException("RegionRenderer: Couldn't init program: "+sp);
- }
- st.attachShaderProgram(gl, sp, false);
- st.bindAttribLocation(gl, AttributeNames.VERTEX_ATTR_IDX, AttributeNames.VERTEX_ATTR_NAME);
- st.bindAttribLocation(gl, AttributeNames.TEXCOORD_ATTR_IDX, AttributeNames.TEXCOORD_ATTR_NAME);
-
- if(!sp.link(gl, System.err)) {
- throw new GLException("TextRendererImpl01: Couldn't link program: "+sp);
- }
- st.useProgram(gl, true);
-
- if(DEBUG) {
- System.err.println("TextRendererImpl01 initialized: " + Thread.currentThread()+" "+st);
- }
- return true;
- }
-
- @Override
- protected void destroyImpl(GL2ES2 gl) {
- super.destroyImpl(gl);
- }
-
- @Override
- public void drawString3D(GL2ES2 gl, Font font, String str, int fontSize, int[/*1*/] texSize) {
- if(!isInitialized()){
- throw new GLException("TextRendererImpl01: not initialized!");
- }
- GlyphString glyphString = getCachedGlyphString(font, str, fontSize);
- if(null == glyphString) {
- glyphString = createString(gl, font, fontSize, str);
- addCachedGlyphString(gl, font, str, fontSize, glyphString);
- }
-
- glyphString.renderString3D(gl, rs, vp_width, vp_height, texSize);
- }
-}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
index 9feb18a12..3cc6152b2 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
@@ -42,7 +42,7 @@ import com.jogamp.opengl.util.glsl.ShaderState;
public class VBORegionSPES2 extends GLRegion {
private GLArrayDataServer verticeAttr = null;
private GLArrayDataServer texCoordAttr = null;
- private GLArrayDataServer indices = null;
+ private GLArrayDataServer indicesBuffer = null;
protected VBORegionSPES2(int renderModes) {
super(renderModes);
@@ -54,11 +54,11 @@ public class VBORegionSPES2 extends GLRegion {
return;
}
- if(null == indices) {
+ if(null == indicesBuffer) {
final int initialElementCount = 256;
final ShaderState st = rs.getShaderState();
- indices = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ indicesBuffer = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
verticeAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT,
false, initialElementCount, GL.GL_STATIC_DRAW);
@@ -73,9 +73,12 @@ public class VBORegionSPES2 extends GLRegion {
}
}
+ if(DEBUG_INSTANCE) {
+ System.err.println("VBORegionSPES2 Indices of "+triangles.size()+", triangles");
+ }
// process triangles
- indices.seal(gl, false);
- indices.rewind();
+ indicesBuffer.seal(gl, false);
+ indicesBuffer.rewind();
for(int i=0; i<triangles.size(); i++) {
final Triangle t = triangles.get(i);
final Vertex[] t_vertices = t.getVertices();
@@ -89,17 +92,25 @@ public class VBORegionSPES2 extends GLRegion {
vertices.add(t_vertices[1]);
vertices.add(t_vertices[2]);
- indices.puts((short) t_vertices[0].getId());
- indices.puts((short) t_vertices[1].getId());
- indices.puts((short) t_vertices[2].getId());
+ indicesBuffer.puts((short) t_vertices[0].getId());
+ indicesBuffer.puts((short) t_vertices[1].getId());
+ indicesBuffer.puts((short) t_vertices[2].getId());
+ if(DEBUG_INSTANCE) {
+ System.err.println("VBORegionSPES2.Indices.1: "+
+ t_vertices[0].getId()+", "+t_vertices[1].getId()+", "+t_vertices[2].getId());
+ }
} else {
- indices.puts((short) t_vertices[0].getId());
- indices.puts((short) t_vertices[1].getId());
- indices.puts((short) t_vertices[2].getId());
+ indicesBuffer.puts((short) t_vertices[0].getId());
+ indicesBuffer.puts((short) t_vertices[1].getId());
+ indicesBuffer.puts((short) t_vertices[2].getId());
+ if(DEBUG_INSTANCE) {
+ System.err.println("VBORegionSPES2.Indices.2: "+
+ t_vertices[0].getId()+", "+t_vertices[1].getId()+", "+t_vertices[2].getId());
+ }
}
}
- indices.seal(gl, true);
- indices.enableBuffer(gl, false);
+ indicesBuffer.seal(gl, true);
+ indicesBuffer.enableBuffer(gl, false);
// process vertices and update bbox
box.reset();
@@ -130,11 +141,11 @@ public class VBORegionSPES2 extends GLRegion {
protected void drawImpl(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int[/*1*/] texWidth) {
verticeAttr.enableBuffer(gl, true);
texCoordAttr.enableBuffer(gl, true);
- indices.bindBuffer(gl, true); // keeps VBO binding
+ indicesBuffer.bindBuffer(gl, true); // keeps VBO binding
- gl.glDrawElements(GL2ES2.GL_TRIANGLES, indices.getElementCount() * indices.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0);
+ gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0);
- indices.bindBuffer(gl, false);
+ indicesBuffer.bindBuffer(gl, false);
texCoordAttr.enableBuffer(gl, false);
verticeAttr.enableBuffer(gl, false);
}
@@ -155,9 +166,9 @@ public class VBORegionSPES2 extends GLRegion {
texCoordAttr.destroy(gl);
texCoordAttr = null;
}
- if(null != indices) {
- indices.destroy(gl);
- indices = null;
+ if(null != indicesBuffer) {
+ indicesBuffer.destroy(gl);
+ indicesBuffer = null;
}
}
}
diff --git a/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java b/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java
index f0910c465..a82c2ee7a 100644
--- a/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java
+++ b/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java
@@ -29,7 +29,7 @@
package jogamp.graph.curve.tess;
import java.util.ArrayList;
-
+import java.util.List;
import com.jogamp.graph.curve.tess.Triangulator;
import com.jogamp.graph.geom.Outline;
@@ -48,11 +48,10 @@ public class CDTriangulator2D implements Triangulator{
protected static final boolean DEBUG = Debug.debug("Triangulation");
- private float sharpness = 0.5f;
+ private final float sharpness = 0.5f;
private ArrayList<Loop> loops;
- private ArrayList<Vertex> vertices;
+ // FIXME ? private ArrayList<Vertex> vertices;
- private ArrayList<Triangle> triangles;
private int maxTriID = 0;
@@ -68,13 +67,12 @@ public class CDTriangulator2D implements Triangulator{
@Override
public void reset() {
maxTriID = 0;
- vertices = new ArrayList<Vertex>();
- triangles = new ArrayList<Triangle>(3);
+ // vertices = new ArrayList<Vertex>();
loops = new ArrayList<Loop>();
}
@Override
- public void addCurve(Outline polyline) {
+ public void addCurve(List<Triangle> sink, Outline polyline) {
Loop loop = null;
if(!loops.isEmpty()) {
@@ -82,27 +80,27 @@ public class CDTriangulator2D implements Triangulator{
}
if(loop == null) {
- GraphOutline outline = new GraphOutline(polyline);
- GraphOutline innerPoly = extractBoundaryTriangles(outline, false);
- vertices.addAll(polyline.getVertices());
+ final GraphOutline outline = new GraphOutline(polyline);
+ final GraphOutline innerPoly = extractBoundaryTriangles(sink, outline, false);
+ // vertices.addAll(polyline.getVertices());
loop = new Loop(innerPoly, VectorUtil.Winding.CCW);
loops.add(loop);
} else {
- GraphOutline outline = new GraphOutline(polyline);
- GraphOutline innerPoly = extractBoundaryTriangles(outline, true);
- vertices.addAll(innerPoly.getVertices());
+ final GraphOutline outline = new GraphOutline(polyline);
+ final GraphOutline innerPoly = extractBoundaryTriangles(sink, outline, true);
+ // vertices.addAll(innerPoly.getVertices());
loop.addConstraintCurve(innerPoly);
}
}
@Override
- public ArrayList<Triangle> generate() {
+ public void generate(List<Triangle> sink) {
for(int i=0;i<loops.size();i++) {
Loop loop = loops.get(i);
int numTries = 0;
int size = loop.computeLoopSize();
while(!loop.isSimplex()){
- Triangle tri = null;
+ final Triangle tri;
if(numTries > size){
tri = loop.cut(false);
}
@@ -115,7 +113,7 @@ public class CDTriangulator2D implements Triangulator{
numTries = 0;
size--;
tri.setId(maxTriID++);
- triangles.add(tri);
+ sink.add(tri);
if(DEBUG){
System.err.println(tri);
}
@@ -127,15 +125,14 @@ public class CDTriangulator2D implements Triangulator{
break;
}
}
- Triangle tri = loop.cut(true);
+ final Triangle tri = loop.cut(true);
if(tri != null) {
- triangles.add(tri);
+ sink.add(tri);
}
}
- return triangles;
}
- private GraphOutline extractBoundaryTriangles(GraphOutline outline, boolean hole) {
+ private GraphOutline extractBoundaryTriangles(List<Triangle> sink, GraphOutline outline, boolean hole) {
GraphOutline innerOutline = new GraphOutline();
ArrayList<GraphVertex> outVertices = outline.getGraphPoint();
int size = outVertices.size();
@@ -146,9 +143,9 @@ public class CDTriangulator2D implements Triangulator{
GraphVertex gv1 = currentVertex;
if(!currentVertex.getPoint().isOnCurve()) {
- Vertex v0 = gv0.getPoint().clone();
- Vertex v2 = gv2.getPoint().clone();
- Vertex v1 = gv1.getPoint().clone();
+ final Vertex v0 = gv0.getPoint().clone();
+ final Vertex v2 = gv2.getPoint().clone();
+ final Vertex v1 = gv1.getPoint().clone();
gv0.setBoundaryContained(true);
gv1.setBoundaryContained(true);
@@ -164,7 +161,7 @@ public class CDTriangulator2D implements Triangulator{
t = new Triangle(v2, v1, v0);
}
t.setId(maxTriID++);
- triangles.add(t);
+ sink.add(t);
if(DEBUG){
System.err.println(t);
}
diff --git a/src/jogl/classes/jogamp/graph/curve/tess/Loop.java b/src/jogl/classes/jogamp/graph/curve/tess/Loop.java
index c1dafc0d1..5810e3bc9 100644
--- a/src/jogl/classes/jogamp/graph/curve/tess/Loop.java
+++ b/src/jogl/classes/jogamp/graph/curve/tess/Loop.java
@@ -37,7 +37,7 @@ import com.jogamp.opengl.math.geom.AABBox;
public class Loop {
private HEdge root = null;
- private AABBox box = new AABBox();
+ private final AABBox box = new AABBox();
private GraphOutline initialOutline = null;
public Loop(GraphOutline polyline, VectorUtil.Winding winding){
@@ -272,13 +272,13 @@ public class Loop {
* @return the triangle iff it satisfies, null otherwise
*/
private Triangle createTriangle(Vertex v1, Vertex v2, Vertex v3, HEdge rootT){
- Triangle t = new Triangle(v1, v2, v3);
+ final Triangle t = new Triangle(v1, v2, v3);
t.setVerticesBoundary(checkVerticesBoundary(rootT));
return t;
}
private boolean[] checkVerticesBoundary(HEdge rootT) {
- boolean[] boundary = new boolean[3];
+ final boolean[] boundary = new boolean[3];
HEdge e1 = rootT;
HEdge e2 = rootT.getNext();
HEdge e3 = rootT.getNext().getNext();
diff --git a/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java b/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java
deleted file mode 100644
index 8c214dd0b..000000000
--- a/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/**
- * Copyright 2010 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 jogamp.graph.curve.text;
-
-import java.util.ArrayList;
-
-import com.jogamp.graph.font.Font.Glyph;
-import com.jogamp.graph.geom.Vertex;
-import com.jogamp.graph.geom.Triangle;
-import com.jogamp.graph.geom.Vertex.Factory;
-import com.jogamp.graph.curve.OutlineShape;
-// import com.jogamp.opengl.math.Quaternion;
-
-public class GlyphShape {
-
- // private Quaternion quat= null;
- private Glyph glyph;
- private OutlineShape shape;
-
- /** Create a new Glyph shape
- * based on Parametric curve control polyline
- */
- public GlyphShape(Vertex.Factory<? extends Vertex> factory){
- this.shape = new OutlineShape(factory);
- this.glyph = null;
- }
-
- /** Create a new GlyphShape from a {@link OutlineShape}
- * @param factory vertex impl factory {@link Factory}
- * @param shape {@link OutlineShape} representation of the Glyph
- */
- public GlyphShape(Vertex.Factory<? extends Vertex> factory, Glyph glyph, OutlineShape shape){
- this(factory);
- this.shape = shape;
- this.shape.transformOutlines(OutlineShape.VerticesState.QUADRATIC_NURBS);
- this.glyph = glyph;
- }
-
- public final void destroy() {
- shape.clear();
- shape = null;
- glyph = null;
- }
-
- public final Vertex.Factory<? extends Vertex> vertexFactory() { return shape.vertexFactory(); }
-
- public final Glyph getGlyph() {
- return glyph;
- }
-
- public final OutlineShape getShape() {
- return shape;
- }
-
- public final int getNumVertices() {
- return shape.getVertices().size();
- }
-
- /** Get the rotational quaternion attached to this Shape.
- * @return the Quaternion Object
- public final Quaternion getQuat() {
- return quat;
- }
-
- /**
- * Set the Quaternion that shall define the rotation
- * of this shape.
- * @param quat
- public final void setQuat(Quaternion quat) {
- this.quat = quat;
- }
- */
-
- /** Triangluate the glyph shape
- * @return ArrayList of triangles which define this shape
- */
- public final ArrayList<Triangle> triangulate(){
- return shape.triangulate();
- }
-
- /** Get the list of Vertices of this Object
- * @return arrayList of Vertices
- */
- public final ArrayList<Vertex> getVertices(){
- return shape.getVertices();
- }
-}
diff --git a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java b/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java
deleted file mode 100644
index 5fb547e69..000000000
--- a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/**
- * Copyright 2010 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 jogamp.graph.curve.text;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.jogamp.graph.font.Font;
-import com.jogamp.graph.geom.Vertex;
-import com.jogamp.graph.geom.Triangle;
-import com.jogamp.graph.geom.Vertex.Factory;
-import com.jogamp.graph.geom.opengl.SVertex;
-
-import javax.media.opengl.GL2ES2;
-
-import jogamp.graph.curve.opengl.RegionFactory;
-import jogamp.graph.geom.plane.AffineTransform;
-
-import com.jogamp.graph.curve.OutlineShape;
-import com.jogamp.graph.curve.Region;
-import com.jogamp.graph.curve.opengl.GLRegion;
-import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.opengl.math.geom.AABBox;
-import com.jogamp.opengl.util.PMVMatrix;
-
-/**
- * @deprecated use {@link com.jogamp.graph.font.Font#getOutlineShapes(java.util.List, CharSequence, float, Factory)},
- * {@link com.jogamp.graph.curve.Region#create(OutlineShape, int)}
- * and a {@link com.jogamp.graph.curve.opengl.RegionRenderer}.
- */
-public class GlyphString {
- /** Static font size for all default font OutlineShape generations via {@link #createString(OutlineShape, Factory, Font, String)}.
- * <p>The actual font size shall be accomplished by the GL PMV matrix.</p>
- */
- public static final int STATIC_FONT_SIZE = 10;
-
- private final ArrayList<GlyphShape> glyphs = new ArrayList<GlyphShape>();
- private final CharSequence str;
- private final String fontname;
- private GLRegion region;
-
- private final SVertex origin = new SVertex();
-
- /**
- * <p>Uses {@link #STATIC_FONT_SIZE}.</p>
- * <p>No caching is performed.</p>
- *
- * @param shape is not null, add all {@link GlyphShape}'s {@link Outline} to this instance.
- * @param vertexFactory vertex impl factory {@link Factory}
- * @param font the target {@link Font}
- * @param str string text
- * @return the created {@link GlyphString} instance
- */
- public static GlyphString createString(OutlineShape shape, Factory<? extends Vertex> vertexFactory, Font font, String str) {
- return createString(shape, vertexFactory, font, STATIC_FONT_SIZE, str);
- }
-
- /**
- * <p>No caching is performed.</p>
- *
- * @param shape is not null, add all {@link GlyphShape}'s {@link Outline} to this instance.
- * @param vertexFactory vertex impl factory {@link Factory}
- * @param font the target {@link Font}
- * @param fontSize font size
- * @param str string text
- * @return the created {@link GlyphString} instance
- */
- public static GlyphString createString(OutlineShape shape, Factory<? extends Vertex> vertexFactory, Font font, int fontSize, CharSequence str) {
- List<OutlineShape> shapes = font.getOutlineShapes(null, str, fontSize, vertexFactory);
-
- GlyphString glyphString = new GlyphString(font.getName(Font.NAME_UNIQUNAME), str);
- glyphString.createfromOutlineShapes(vertexFactory, font, str, shapes);
- if(null != shape) {
- for(int i=0; i<glyphString.glyphs.size(); i++) {
- shape.addOutlineShape(glyphString.glyphs.get(i).getShape());
- }
- }
- return glyphString;
- }
-
- /** Create a new GlyphString object
- * @param fontname the name of the font that this String is
- * associated with
- * @param str the string object
- */
- public GlyphString(String fontname, CharSequence str){
- this.fontname = fontname;
- this.str = str;
- }
-
- public void addGlyphShape(GlyphShape glyph){
- glyphs.add(glyph);
- }
-
- public CharSequence getString(){
- return str;
- }
-
- /**Creates the Curve based Glyphs from a list of {@link OutlineShape}
- * @param vertexFactory vertex impl factory {@link Factory}
- * @param shapes list of {@link OutlineShape}
- */
- public void createfromOutlineShapes(Factory<? extends Vertex> vertexFactory, Font font, CharSequence str, List<OutlineShape> shapes) {
- if(shapes.size() != str.length()) {
- throw new InternalError("XXX");
- }
- final int numGlyps = shapes.size();
- for (int index=0;index<numGlyps;index++){
- if(shapes.get(index) == null){
- continue;
- }
- GlyphShape glyphShape = new GlyphShape(vertexFactory,
- font.getGlyph(str.charAt(index)),
- shapes.get(index));
-
- if(glyphShape.getNumVertices() < 3) {
- continue;
- }
- addGlyphShape(glyphShape);
- }
- }
-
-
- /** Generate a OGL Region to represent this Object.
- * @param gl the current gl object
- * @param rs the current attached RenderState
- * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#VBAA_RENDERING_BIT}
- */
- public GLRegion createRegion(GL2ES2 gl, int renderModes){
- region = RegionFactory.create(renderModes);
- // region.setFlipped(true);
- float y = 0;
- float advanceTotal = 0;
- AffineTransform t = new AffineTransform();
-
- int numVertices = region.getNumVertices();
-
- for(int i=0; i< glyphs.size(); i++) {
- final GlyphShape glyphShape = glyphs.get(i);
- Font.Metrics metrics = glyphShape.getGlyph().getFont().getMetrics();
- final float scale = metrics.getScale(STATIC_FONT_SIZE);
- t.translate(advanceTotal, y);
- t.scale(scale, scale);
-
- ArrayList<Triangle> gtris = glyphShape.triangulate();
- region.addTriangles(gtris);
-
- final ArrayList<Vertex> gVertices = glyphShape.getVertices();
- for(int j=0; j<gVertices.size(); j++) {
- final Vertex gVert = gVertices.get(j);
- gVert.setId(numVertices++);
- region.addVertex(gVert);
- }
-
- advanceTotal += glyphShape.getGlyph().getAdvance(STATIC_FONT_SIZE, true);
- }
- return region;
- }
-
- /** Generate a Hashcode for this object
- * @return a string defining the hashcode
- */
- public String getTextHashCode(){
- return "" + fontname.hashCode() + str.hashCode();
- }
-
- /** Render the Object based using the associated Region
- * previously generated.
- */
- public void renderString3D(GL2ES2 gl) {
- region.draw(gl, null, 0, 0, null);
- }
- /** Render the Object based using the associated Region
- * previously generated.
- * @param matrix current {@link PMVMatrix}.
- * @param rs the RenderState to be used
- * @param vp_width current screen width
- * @param vp_height current screen height
- * @param texWidth desired texture width for multipass-rendering.
- * The actual used texture-width is written back when mp rendering is enabled, otherwise the store is untouched.
- */
- public void renderString3D(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int[/*1*/] texWidth) {
- region.draw(gl, rs, vp_width, vp_height, texWidth);
- }
-
- /** Get the Origin of this GlyphString
- * @return
- */
- public Vertex getOrigin() {
- return origin;
- }
-
- /** Destroy the associated OGL objects
- * @param rs the current attached RenderState
- */
- public void destroy(GL2ES2 gl, RenderState rs) {
- if(null != gl && null != rs) {
- region.destroy(gl, rs);
- region = null;
- } else if(null != region) {
- throw new InternalError("destroy called w/o GL context, but has a region");
- }
- glyphs.clear();
- }
-
- public AABBox getBounds(){
- return region.getBounds();
- }
-}
diff --git a/src/jogl/classes/jogamp/graph/font/FontInt.java b/src/jogl/classes/jogamp/graph/font/FontInt.java
index 1f4eaf20d..f87a00251 100644
--- a/src/jogl/classes/jogamp/graph/font/FontInt.java
+++ b/src/jogl/classes/jogamp/graph/font/FontInt.java
@@ -31,6 +31,9 @@ import jogamp.graph.geom.plane.Path2D;
import com.jogamp.graph.font.Font;
+/**
+ * @deprecated
+ */
public interface FontInt extends Font {
public interface GlyphInt extends Font.Glyph {
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
index 250778f06..41fa6c223 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
@@ -44,19 +44,20 @@ import com.jogamp.common.util.IntObjectHashMap;
import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontFactory;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.geom.Vertex.Factory;
import com.jogamp.opengl.math.geom.AABBox;
class TypecastFont implements FontInt {
static final boolean DEBUG = false;
+ private static final Vertex.Factory<SVertex> vertexFactory = SVertex.factory();
final OTFontCollection fontset;
final OTFont font;
TypecastHMetrics metrics;
final CmapFormat cmapFormat;
int cmapentries;
-
// FIXME: Add cache size to limit memory usage ??
IntObjectHashMap char2Glyph;
@@ -201,8 +202,10 @@ class TypecastFont implements FontInt {
if(null == glyph) {
throw new RuntimeException("Could not retrieve glyph for symbol: <"+symbol+"> "+(int)symbol+" -> glyph id "+code);
}
- Path2D path = TypecastRenderer.buildPath(glyph);
- result = new TypecastGlyph(this, symbol, code, glyph.getBBox(), glyph.getAdvanceWidth(), path);
+ final OutlineShape shape = TypecastRenderer.buildShape(glyph, vertexFactory);
+ // FIXME: Remove Path2D
+ final Path2D path = TypecastRenderer.buildPath(glyph);
+ result = new TypecastGlyph(this, symbol, code, glyph.getBBox(), glyph.getAdvanceWidth(), path, shape);
if(DEBUG) {
System.err.println("New glyph: " + (int)symbol + " ( " + symbol +" ) -> " + code + ", contours " + glyph.getPointCount() + ": " + path);
}
@@ -225,11 +228,7 @@ class TypecastFont implements FontInt {
return result;
}
- @Override
- public OutlineShape getOutlineShape(Glyph glyph, Factory<? extends Vertex> vertexFactory) {
- return TypecastRenderer.getOutlineShape(this, glyph, vertexFactory);
- }
-
+ // FIXME: Remove altogether
@Override
public List<OutlineShape> getOutlineShapes(List<OutlineShape> shapes, CharSequence string, float pixelSize, Factory<? extends Vertex> vertexFactory) {
AffineTransform transform = new AffineTransform(vertexFactory);
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java
index 302366647..40727826b 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java
@@ -33,6 +33,7 @@ import jogamp.graph.font.FontInt;
import jogamp.graph.geom.plane.AffineTransform;
import jogamp.graph.geom.plane.Path2D;
+import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.graph.font.Font;
import com.jogamp.opengl.math.geom.AABBox;
@@ -136,30 +137,36 @@ public class TypecastGlyph implements FontInt.GlyphInt {
public static final short MAX_ID = (short)((1 << 16) - 2);
private final Font font;
+ protected final char symbol;
+ protected final OutlineShape shape; // in EM units
+
+ protected final Path2D path; // in EM units FIXME remove!
- char symbol;
short id;
int advance;
Metrics metrics;
- protected Path2D path; // in EM units
- protected Path2D pathSized;
- protected float numberSized;
+ protected Path2D pathSized; // FIXME remove!
+ protected float numberSized; // FIXME remove!
protected TypecastGlyph(Font font, char symbol) {
this.font = font;
this.symbol = symbol;
+ this.shape = null;
+ this.path = null;
}
protected TypecastGlyph(Font font,
- char symbol, short id, AABBox bbox, int advance, Path2D path) {
+ char symbol, short id, AABBox bbox, int advance, Path2D path, OutlineShape shape) {
this.font = font;
this.symbol = symbol;
+ this.shape = shape;
+ this.path = path;
+
this.advance = advance;
init(id, bbox, advance);
- this.path = path;
this.pathSized = null;
this.numberSized = 0.0f;
}
@@ -170,10 +177,11 @@ public class TypecastGlyph implements FontInt.GlyphInt {
this.metrics = new Metrics(this.font, bbox, this.advance);
}
+ /**
public void reset(Path2D path) {
this.path = path;
this.metrics.reset();
- }
+ } */
@Override
public Font getFont() {
@@ -223,6 +231,11 @@ public class TypecastGlyph implements FontInt.GlyphInt {
}
@Override
+ public OutlineShape getShape() {
+ return this.shape;
+ }
+
+ @Override
public Path2D getPath() {
return this.path;
}
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java
index d7f8497b3..83ccadab3 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java
@@ -55,25 +55,27 @@ public class TypecastRenderer {
if (string == null) {
return;
}
- Font.Metrics metrics = font.getMetrics();
- float advanceTotal = 0;
- float lineGap = metrics.getLineGap(pixelSize) ;
- float ascent = metrics.getAscent(pixelSize) ;
- float descent = metrics.getDescent(pixelSize) ;
+ final Font.Metrics metrics = font.getMetrics();
+ final float lineGap = metrics.getLineGap(pixelSize) ;
+ final float ascent = metrics.getAscent(pixelSize) ;
+ final float descent = metrics.getDescent(pixelSize) ;
+ final float advanceY = lineGap - descent + ascent;
+ final float scale = metrics.getScale(pixelSize);
if (transform == null) {
transform = new AffineTransform();
}
- AffineTransform t = new AffineTransform();
+ final AffineTransform t = new AffineTransform(transform.getFactory());
final int len = string.length();
- float advanceY = lineGap - descent + ascent;
+
+ float advanceTotal = 0;
float y = 0;
+
for (int i=0; i<len; i++)
{
p[i] = new Path2D();
p[i].reset();
- t.setTransform(transform);
- char character = string.charAt(i);
+ final char character = string.charAt(i);
if (character == '\n') {
y += advanceY;
advanceTotal = 0;
@@ -82,7 +84,7 @@ public class TypecastRenderer {
} else {
final Glyph glyph = font.getGlyph(character);
final Path2D gp = ((GlyphInt)glyph).getPath();
- final float scale = metrics.getScale(pixelSize);
+ t.setTransform(transform); // reset transform
t.translate(advanceTotal, y);
t.scale(scale, scale);
p[i].append(gp.iterator(t), false);
@@ -92,6 +94,7 @@ public class TypecastRenderer {
}
public static OutlineShape getOutlineShape(TypecastFont font, Glyph glyph, Factory<? extends Vertex> vertexFactory) {
+ // FIXME: Remove Path2D
Path2D path = ((GlyphInt)glyph).getPath();
AffineTransform transform = new AffineTransform(vertexFactory);
OutlineShape shape = new OutlineShape(vertexFactory);
@@ -109,6 +112,8 @@ public class TypecastRenderer {
}
public static List<OutlineShape> getOutlineShapes(List<OutlineShape> shapes, TypecastFont font, CharSequence string, float pixelSize, AffineTransform transform, Factory<? extends Vertex> vertexFactory) {
+ // FIXME: Remove Path2D
+ // FIXME: Remove altogether
Path2D[] paths = new Path2D[string.length()];
getPaths(font, string, pixelSize, transform, paths);
@@ -161,6 +166,118 @@ public class TypecastRenderer {
}
}
+ private static void addShapeMoveTo(final OutlineShape shape, Factory<? extends Vertex> vertexFactory, Point p1) {
+ shape.closeLastOutline();
+ shape.addEmptyOutline();
+ shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, true)); // p1.onCurve));
+ // shape.addVertex(0, vertexFactory.create(coords, 0, 2, true));
+ }
+ private static void addShapeLineTo(final OutlineShape shape, Factory<? extends Vertex> vertexFactory, Point p1) {
+ shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, true)); // p1.onCurve));
+ // shape.addVertex(0, vertexFactory.create(coords, 0, 2, true));
+ }
+ private static void addShapeQuadTo(final OutlineShape shape, Factory<? extends Vertex> vertexFactory, Point p1, Point p2) {
+ shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, false)); // p1.onCurve));
+ shape.addVertex(0, vertexFactory.create(p2.x, p2.y, 0, true)); // p2.onCurve));
+ // shape.addVertex(0, vertexFactory.create(coords, 0, 2, false));
+ // shape.addVertex(0, vertexFactory.create(coords, 2, 2, true));
+ }
+ private static void addShapeQuadTo(final OutlineShape shape, Factory<? extends Vertex> vertexFactory, Point p1, int p2x, int p2y) {
+ shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, false)); // p1.onCurve));
+ shape.addVertex(0, vertexFactory.create(p2x, p2y, 0, true)); // p2.onCurve));
+ // shape.addVertex(0, vertexFactory.create(coords, 0, 2, false));
+ // shape.addVertex(0, vertexFactory.create(coords, 2, 2, true));
+ }
+ /**
+ private static void addShapeCubicTo(final OutlineShape shape, Factory<? extends Vertex> vertexFactory, Point p1, Point p2, Point p3) {
+ shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, false)); // p1.onCurve));
+ shape.addVertex(0, vertexFactory.create(p2.x, p2.y, 0, false)); // p2.onCurve));
+ shape.addVertex(0, vertexFactory.create(p3.x, p3.y, 0, true)); // p3.onCurve));
+ // shape.addVertex(0, vertexFactory.create(coords, 0, 2, false));
+ // shape.addVertex(0, vertexFactory.create(coords, 2, 2, false));
+ // shape.addVertex(0, vertexFactory.create(coords, 4, 2, true));
+
+ }
+ private static void addShapeClose(final OutlineShape shape, Factory<? extends Vertex> vertexFactory) {
+ shape.closeLastOutline();
+ } */
+
+ public static OutlineShape buildShape(OTGlyph glyph, Factory<? extends Vertex> vertexFactory) {
+
+ if (glyph == null) {
+ return null;
+ }
+
+ final OutlineShape shape = new OutlineShape(vertexFactory);
+
+ // Iterate through all of the points in the glyph. Each time we find a
+ // contour end point, add the point range to the path.
+ int startIndex = 0;
+ int count = 0;
+ for (int i = 0; i < glyph.getPointCount(); i++) {
+ count++;
+ if (glyph.getPoint(i).endOfContour) {
+ {
+ int offset = 0;
+ while (offset < count) {
+ final Point point = glyph.getPoint(startIndex + offset%count);
+ final Point point_plus1 = glyph.getPoint(startIndex + (offset+1)%count);
+ final Point point_plus2 = glyph.getPoint(startIndex + (offset+2)%count);
+ if(offset == 0)
+ {
+ addShapeMoveTo(shape, vertexFactory, point);
+ // gp.moveTo(point.x, point.y);
+ }
+
+ if (point.onCurve) {
+ if (point_plus1.onCurve) {
+ // s = new Line2D.Float(point.x, point.y, point_plus1.x, point_plus1.y);
+ addShapeLineTo(shape, vertexFactory, point_plus1);
+ // gp.lineTo( point_plus1.x, point_plus1.y );
+ offset++;
+ } else {
+ if (point_plus2.onCurve) {
+ // s = new QuadCurve2D.Float( point.x, point.y, point_plus1.x, point_plus1.y, point_plus2.x, point_plus2.y);
+ addShapeQuadTo(shape, vertexFactory, point_plus1, point_plus2);
+ // gp.quadTo(point_plus1.x, point_plus1.y, point_plus2.x, point_plus2.y);
+ offset+=2;
+ } else {
+ // s = new QuadCurve2D.Float(point.x,point.y,point_plus1.x,point_plus1.y,
+ // midValue(point_plus1.x, point_plus2.x), midValue(point_plus1.y, point_plus2.y));
+ addShapeQuadTo(shape, vertexFactory, point_plus1, midValue(point_plus1.x, point_plus2.x), midValue(point_plus1.y, point_plus2.y));
+ // gp.quadTo(point_plus1.x, point_plus1.y, midValue(point_plus1.x, point_plus2.x), midValue(point_plus1.y, point_plus2.y));
+ offset+=2;
+ }
+ }
+ } else {
+ if (point_plus1.onCurve) {
+ // s = new QuadCurve2D.Float(midValue(point_minus1.x, point.x), midValue(point_minus1.y, point.y),
+ // point.x, point.y, point_plus1.x, point_plus1.y);
+ //gp.curve3(point_plus1.x, point_plus1.y, point.x, point.y);
+ addShapeQuadTo(shape, vertexFactory, point, point_plus1);
+ // gp.quadTo(point.x, point.y, point_plus1.x, point_plus1.y);
+ offset++;
+
+ } else {
+ // s = new QuadCurve2D.Float(midValue(point_minus1.x, point.x), midValue(point_minus1.y, point.y), point.x, point.y,
+ // midValue(point.x, point_plus1.x), midValue(point.y, point_plus1.y));
+ //gp.curve3(midValue(point.x, point_plus1.x), midValue(point.y, point_plus1.y), point.x, point.y);
+ addShapeQuadTo(shape, vertexFactory, point, midValue(point.x, point_plus1.x), midValue(point.y, point_plus1.y));
+ // gp.quadTo(point.x, point.y, midValue(point.x, point_plus1.x), midValue(point.y, point_plus1.y));
+ offset++;
+ }
+ }
+ }
+
+ }
+ startIndex = i + 1;
+ count = 0;
+ }
+ }
+ shape.closeLastOutline();
+ return shape;
+ }
+
/**
* Build a {@link com.jogamp.graph.geom.Path2D Path2D} from a
* {@link jogamp.graph.font.typecast.ot.OTGlyph Glyph}. This glyph path can then
diff --git a/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java b/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java
index 32e2b6a39..f5cf8dd95 100644
--- a/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java
+++ b/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java
@@ -121,6 +121,8 @@ public class AffineTransform implements Cloneable, Serializable {
}
}
+ public final Vertex.Factory<? extends Vertex> getFactory() { return pointFactory; }
+
/*
* Method returns type of affine transformation.
*
@@ -403,12 +405,10 @@ public class AffineTransform implements Cloneable, Serializable {
public Vertex transform(Vertex src, Vertex dst) {
if (dst == null) {
- dst = pointFactory.create();
+ dst = pointFactory.create(src.getId(), src.isOnCurve(), src.getTexCoord());
}
-
- float x = src.getX();
- float y = src.getY();
-
+ final float x = src.getX();
+ final float y = src.getY();
dst.setCoord(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12, 0f);
return dst;
}
@@ -416,12 +416,12 @@ public class AffineTransform implements Cloneable, Serializable {
public void transform(Vertex[] src, int srcOff, Vertex[] dst, int dstOff, int length) {
while (--length >= 0) {
Vertex srcPoint = src[srcOff++];
- float x = srcPoint.getX();
- float y = srcPoint.getY();
Vertex dstPoint = dst[dstOff];
if (dstPoint == null) {
throw new IllegalArgumentException("dst["+dstOff+"] is null");
}
+ final float x = srcPoint.getX();
+ final float y = srcPoint.getY();
dstPoint.setCoord(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12, 0f);
dst[dstOff++] = dstPoint;
}
@@ -446,12 +446,10 @@ public class AffineTransform implements Cloneable, Serializable {
public Vertex deltaTransform(Vertex src, Vertex dst) {
if (dst == null) {
- dst = pointFactory.create();
+ dst = pointFactory.create(src.getId(), src.isOnCurve(), src.getTexCoord());
}
-
- float x = src.getX();
- float y = src.getY();
-
+ final float x = src.getX();
+ final float y = src.getY();
dst.setCoord(x * m00 + y * m01, x * m10 + y * m11, 0f);
return dst;
}
@@ -471,12 +469,10 @@ public class AffineTransform implements Cloneable, Serializable {
throw new NoninvertibleTransformException(determinantIsZero);
}
if (dst == null) {
- dst = pointFactory.create();
+ dst = pointFactory.create(src.getId(), src.isOnCurve(), src.getTexCoord());
}
-
- float x = src.getX() - m02;
- float y = src.getY() - m12;
-
+ final float x = src.getX() - m02;
+ final float y = src.getY() - m12;
dst.setCoord((x * m11 - y * m01) / det, (y * m00 - x * m10) / det, 0f);
return dst;
}
@@ -502,7 +498,7 @@ public class AffineTransform implements Cloneable, Serializable {
return null;
}
if (src instanceof Path2D) {
- return ((Path2D)src).createTransformedShape(this);
+ return src.createTransformedShape(this);
}
PathIterator path = src.iterator(this);
Path2D dst = new Path2D(path.getWindingRule());
diff --git a/src/jogl/classes/jogamp/graph/geom/plane/Path2D.java b/src/jogl/classes/jogamp/graph/geom/plane/Path2D.java
index 33b80d6b8..a87c0a0a1 100644
--- a/src/jogl/classes/jogamp/graph/geom/plane/Path2D.java
+++ b/src/jogl/classes/jogamp/graph/geom/plane/Path2D.java
@@ -21,8 +21,8 @@ package jogamp.graph.geom.plane;
import java.util.NoSuchElementException;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.graph.geom.Vertex;
-import com.jogamp.graph.geom.opengl.SVertex;
import com.jogamp.opengl.math.geom.AABBox;
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 9942f3f1d..a1cd54de2 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java
@@ -44,7 +44,7 @@ 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.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.test.junit.graph.demos.GPURegionGLListener01;
import com.jogamp.opengl.test.junit.graph.demos.GPURegionGLListener02;
@@ -80,7 +80,7 @@ public class TestRegionRendererNEWT01 extends UITestCase {
return window;
}
- @Test
+ // @Test
public void test00RegionRendererNONE01() throws InterruptedException {
GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
GLCapabilities caps = new GLCapabilities(glp);
@@ -109,7 +109,7 @@ public class TestRegionRendererNEWT01 extends UITestCase {
destroyWindow(window);
}
- @Test
+ // @Test
public void test01RegionRendererNONE02() throws InterruptedException {
if(Platform.CPUFamily.X86 != Platform.CPU_ARCH.family) { // FIXME
// FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise).
@@ -174,7 +174,7 @@ public class TestRegionRendererNEWT01 extends UITestCase {
destroyWindow(window);
}
- @Test
+ // @Test
public void test11RegionRendererMSAA02() throws InterruptedException {
if(Platform.CPUFamily.X86 != Platform.CPU_ARCH.family) { // FIXME
// FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise).
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java
index 826c08ed4..7e151945c 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java
@@ -34,10 +34,10 @@ import java.io.StringWriter;
import javax.media.opengl.GL;
import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GLAnimatorControl;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLCapabilitiesImmutable;
-import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLException;
import javax.media.opengl.GLProfile;
import javax.media.opengl.GLRunnable;
@@ -48,14 +48,15 @@ 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.curve.opengl.TextRenderer;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontFactory;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.newt.opengl.GLWindow;
-import com.jogamp.opengl.math.geom.AABBox;
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.glsl.ShaderState;
@@ -65,8 +66,8 @@ public class TestTextRendererNEWT00 extends UITestCase {
static final boolean DEBUG = false;
static final boolean TRACE = false;
static long duration = 100; // ms
-
- static final int[] texSize = new int[] { 0 };
+
+ static final int[] texSize = new int[] { 0 };
static final int fontSize = 24;
static Font font;
@@ -74,13 +75,13 @@ public class TestTextRendererNEWT00 extends UITestCase {
public static void setup() throws IOException {
font = FontFactory.get(FontFactory.UBUNTU).getDefault();
}
-
+
static int atoi(String a) {
try {
return Integer.parseInt(a);
} catch (Exception ex) { throw new RuntimeException(ex); }
}
-
+
public static void main(String args[]) throws IOException {
for(int i=0; i<args.length; i++) {
if(args[i].equals("-time")) {
@@ -90,15 +91,15 @@ public class TestTextRendererNEWT00 extends UITestCase {
}
String tstname = TestTextRendererNEWT00.class.getName();
org.junit.runner.JUnitCore.main(tstname);
- }
-
+ }
+
static void sleep() {
try {
System.err.println("** new frame ** (sleep: "+duration+"ms)");
Thread.sleep(duration);
} catch (InterruptedException ie) {}
}
-
+
static void destroyWindow(GLWindow window) {
if(null!=window) {
window.destroy();
@@ -117,12 +118,12 @@ public class TestTextRendererNEWT00 extends UITestCase {
return window;
}
-
+
@Test
public void testTextRendererMSAA01() throws InterruptedException {
GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
GLCapabilities caps = new GLCapabilities(glp);
- caps.setAlphaBits(4);
+ caps.setAlphaBits(4);
caps.setSampleBuffers(true);
caps.setNumSamples(4);
System.err.println("Requested: "+caps);
@@ -130,109 +131,114 @@ public class TestTextRendererNEWT00 extends UITestCase {
GLWindow window = createWindow("text-vbaa0-msaa1", caps, 800, 400);
window.display();
System.err.println("Chosen: "+window.getChosenGLCapabilities());
-
+
final RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
- final TextRendererListener textGLListener = new TextRendererListener(rs);
- final TextRenderer renderer = textGLListener.getRenderer();
+ final TextRendererGLEL textGLListener = new TextRendererGLEL(rs);
+ System.err.println(textGLListener.getFontInfo());
+
window.addGLEventListener(textGLListener);
window.invoke(true, new GLRunnable() {
@Override
public boolean run(GLAutoDrawable drawable) {
- int c=0;
- renderString(drawable, renderer, "GlueGen", c++, -1, -1000);
- renderString(drawable, renderer, "JOAL", c++, -1, -1000);
- renderString(drawable, renderer, "JOGL", c++, -1, -1000);
- renderString(drawable, renderer, "JOCL", c++, -1, -1000);
try {
textGLListener.printScreen(drawable, "./", "TestTextRendererNEWT00-snap"+screenshot_num, false);
+ screenshot_num++;
} catch (Exception e) {
e.printStackTrace();
}
return true;
- }
+ }
});
- sleep();
-
- destroyWindow(window);
- }
- int screenshot_num = 0;
-
- int lastRow = -1;
-
- void renderString(GLAutoDrawable drawable, TextRenderer renderer, String text, int column, int row, int z0) {
- final GL2ES2 gl = drawable.getGL().getGL2ES2();
- final int height = drawable.getHeight();
-
- int dx = 0;
- int dy = height;
- if(0>row) {
- row = lastRow + 1;
- }
- AABBox textBox = font.getStringBounds(text, fontSize);
- dx += font.getAdvanceWidth('X', fontSize) * column;
- dy -= (int)textBox.getHeight() * ( row + 1 );
- renderer.resetModelview(null);
- renderer.translate(gl, dx, dy, z0);
- renderer.drawString3D(gl, font, text, fontSize, texSize);
-
- lastRow = row;
+ Animator anim = new Animator();
+ anim.add(window);
+ anim.start();
+ anim.setUpdateFPSFrames(60, null);
+ sleep();
+ anim.stop();
+ destroyWindow(window);
}
-
- public class TextRendererListener implements GLEventListener {
- private GLReadBufferUtil screenshot;
- private TextRenderer renderer;
-
- public TextRendererListener(RenderState rs) {
+ int screenshot_num = 0;
+
+ private final class TextRendererGLEL extends TextRendererGLELBase {
+ private final GLReadBufferUtil screenshot;
+ private long t0;
+
+ TextRendererGLEL(final RenderState rs) {
+ super(rs, true /* exclusivePMV */, 0); // Region.VBAA_RENDERING_BIT);
+ texSizeScale = 2;
+
+ fontSize = 24;
+
+ staticRGBAColor[0] = 0.0f;
+ staticRGBAColor[1] = 0.0f;
+ staticRGBAColor[2] = 0.0f;
+ staticRGBAColor[3] = 1.0f;
+
this.screenshot = new GLReadBufferUtil(false, false);
- this.renderer = TextRenderer.create(rs, 0);
}
-
- public final TextRenderer getRenderer() { return renderer; }
-
+
+ @Override
+ public void init(GLAutoDrawable drawable) {
+ super.init(drawable);
+ drawable.getGL().setSwapInterval(0);
+ t0 = Platform.currentTimeMillis();
+ }
+ public void dispose(GLAutoDrawable drawable) {
+ final GL2ES2 gl = drawable.getGL().getGL2ES2();
+ screenshot.dispose(gl);
+ super.dispose(drawable);
+ }
+
public void printScreen(GLAutoDrawable drawable, String dir, String objName, boolean exportAlpha) throws GLException, IOException {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
pw.printf("%s-%03dx%03d-T%04d", objName, drawable.getWidth(), drawable.getHeight(), texSize[0]);
-
+
final String filename = dir + sw +".png";
if(screenshot.readPixels(drawable.getGL(), false)) {
screenshot.write(new File(filename));
}
}
-
- public void init(GLAutoDrawable drawable) {
- final GL2ES2 gl = drawable.getGL().getGL2ES2();
- gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
- renderer.init(gl);
- renderer.setAlpha(gl, 1.0f);
- renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
- }
-
- public void reshape(GLAutoDrawable drawable, int xstart, int ystart, int width, int height) {
- final GL2ES2 gl = drawable.getGL().getGL2ES2();
-
- gl.glViewport(xstart, ystart, width, height);
- // renderer.reshapePerspective(gl, 45.0f, width, height, 0.1f, 1000.0f);
- renderer.reshapeOrtho(gl, width, height, 0.1f, 1000.0f);
+
+ String getFontInfo() {
+ final float unitsPerEM_Inv = font.getMetrics().getScale(1f);
+ final float unitsPerEM = 1f / unitsPerEM_Inv;
+ return String.format("Font %s, unitsPerEM %f", font.getName(Font.NAME_UNIQUNAME), unitsPerEM);
}
-
+
+ @Override
public void display(GLAutoDrawable drawable) {
- final GL2ES2 gl = drawable.getGL().getGL2ES2();
+ 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);
-
- renderString(drawable, renderer, "012345678901234567890123456789", 0, 0, -1000);
- renderString(drawable, renderer, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, -1, -1000);
- renderString(drawable, renderer, "Hello World", 0, -1, -1000);
- renderString(drawable, renderer, "4567890123456", 4, -1, -1000);
- renderString(drawable, renderer, "I like JogAmp", 4, -1, -1000);
- }
-
- public void dispose(GLAutoDrawable drawable) {
- final GL2ES2 gl = drawable.getGL().getGL2ES2();
- screenshot.dispose(gl);
- renderer.destroy(gl);
- }
- }
+
+ 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 String text1 = String.format("%03.3f/%03.3f s, vsync %d, elapsed %4.4f s",
+ lfps, tfps, gl.getSwapInterval(), (t1-t0)/1000.0);
+
+ int row = 0;
+ if( false ) {
+ renderString(drawable, "112", 0, row++, 0, 0, -1000);
+ // renderString(drawable, getFontInfo(), 0, row++, 0, 0, -1000);
+ } else {
+ renderString(drawable, getFontInfo(), 0, row++, 0, 0, -1000);
+ renderString(drawable, "012345678901234567890123456789", 0, row++, 0, 0, -1000);
+ renderString(drawable, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, row++, 0, 0, -1000);
+ renderString(drawable, "Hello World", 0, row++, 0, 0, -1000);
+ renderString(drawable, "4567890123456", 4, row++, 0, 0, -1000);
+ renderString(drawable, "I like JogAmp", 4, row++, 0, 0, -1000);
+ renderString(drawable, "Hello World", 0, row++, 0, 0, -1000);
+ renderString(drawable, text1, 0, row++, 0, 0, -1000);
+ }
+ } };
}
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 75a672a5b..9e15746a6 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java
@@ -45,9 +45,10 @@ 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.curve.opengl.TextRenderer;
+import com.jogamp.graph.curve.opengl.Renderer;
+import com.jogamp.graph.curve.opengl.TextRenderUtil;
import com.jogamp.graph.font.FontFactory;
-import com.jogamp.graph.geom.opengl.SVertex;
+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;
@@ -65,7 +66,7 @@ public class TestTextRendererNEWT01 extends UITestCase {
return Integer.parseInt(a);
} catch (Exception ex) { throw new RuntimeException(ex); }
}
-
+
public static void main(String args[]) throws IOException {
for(int i=0; i<args.length; i++) {
if(args[i].equals("-time")) {
@@ -75,15 +76,15 @@ public class TestTextRendererNEWT01 extends UITestCase {
}
String tstname = TestTextRendererNEWT01.class.getName();
org.junit.runner.JUnitCore.main(tstname);
- }
-
+ }
+
static void sleep() {
try {
System.err.println("** new frame ** (sleep: "+duration+"ms)");
Thread.sleep(duration);
} catch (InterruptedException ie) {}
}
-
+
static void destroyWindow(GLWindow window) {
if(null!=window) {
window.destroy();
@@ -111,29 +112,29 @@ public class TestTextRendererNEWT01 extends UITestCase {
return;
}
GLProfile glp = GLProfile.getGL2ES2();
-
+
GLCapabilities caps = new GLCapabilities(glp);
- caps.setAlphaBits(4);
+ caps.setAlphaBits(4);
System.err.println("Requested: "+caps);
GLWindow window = createWindow("text-vbaa1-msaa0", caps, 800,400);
window.display();
System.err.println("Chosen: "+window.getChosenGLCapabilities());
-
+
RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
TextGLListener textGLListener = new TextGLListener(rs, Region.VBAA_RENDERING_BIT, DEBUG, TRACE);
textGLListener.attachInputListenerTo(window);
window.addGLEventListener(textGLListener);
-
+
if(textGLListener.setFontSet(FontFactory.UBUNTU, 0, 0)) {
textGLListener.setTech(-400, -30, 0f, -1000, window.getWidth()*2);
window.display();
sleep();
-
+
textGLListener.setTech(-400, -30, 0, -380, window.getWidth()*3);
window.display();
sleep();
-
+
textGLListener.setTech(-400, -20, 0, -80, window.getWidth()*4);
window.display();
sleep();
@@ -143,24 +144,24 @@ public class TestTextRendererNEWT01 extends UITestCase {
textGLListener.setTech(-400, -30, 0f, -1000, window.getWidth()*2);
window.display();
sleep();
-
+
textGLListener.setTech(-400, -30, 0, -380, window.getWidth()*3);
window.display();
sleep();
-
+
textGLListener.setTech(-400, -20, 0, -80, window.getWidth()*4);
window.display();
sleep();
}
-
- destroyWindow(window);
+
+ destroyWindow(window);
}
-
+
@Test
public void testTextRendererMSAA01() throws InterruptedException {
GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
GLCapabilities caps = new GLCapabilities(glp);
- caps.setAlphaBits(4);
+ caps.setAlphaBits(4);
caps.setSampleBuffers(true);
caps.setNumSamples(4);
System.err.println("Requested: "+caps);
@@ -168,21 +169,21 @@ public class TestTextRendererNEWT01 extends UITestCase {
GLWindow window = createWindow("text-vbaa0-msaa1", caps, 800, 400);
window.display();
System.err.println("Chosen: "+window.getChosenGLCapabilities());
-
+
RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
TextGLListener textGLListener = new TextGLListener(rs, 0, DEBUG, TRACE);
textGLListener.attachInputListenerTo(window);
window.addGLEventListener(textGLListener);
-
+
if(textGLListener.setFontSet(FontFactory.UBUNTU, 0, 0)) {
textGLListener.setTech(-400, -30, 0f, -1000, 0);
window.display();
sleep();
-
+
textGLListener.setTech(-400, -30, 0, -380, 0);
window.display();
sleep();
-
+
textGLListener.setTech(-400, -20, 0, -80, 0);
window.display();
sleep();
@@ -192,47 +193,47 @@ public class TestTextRendererNEWT01 extends UITestCase {
textGLListener.setTech(-400, -30, 0f, -1000, 0);
window.display();
sleep();
-
+
textGLListener.setTech(-400, -30, 0, -380, 0);
window.display();
sleep();
-
+
textGLListener.setTech(-400, -20, 0, -80, 0);
window.display();
sleep();
}
-
- destroyWindow(window);
+
+ destroyWindow(window);
}
-
+
private class TextGLListener extends GPUTextRendererListenerBase01 {
String winTitle;
-
+
public TextGLListener(RenderState rs, int type, boolean debug, boolean trace) {
super(rs, type, debug, trace);
}
-
+
public void attachInputListenerTo(GLWindow window) {
super.attachInputListenerTo(window);
winTitle = window.getTitle();
}
public void setTech(float xt, float yt, float angle, int zoom, int fboSize){
- setMatrix(xt, yt, angle, zoom, fboSize);
+ setMatrix(xt, yt, angle, zoom, fboSize);
}
public void init(GLAutoDrawable drawable) {
super.init(drawable);
-
+
GL2ES2 gl = drawable.getGL().getGL2ES2();
gl.setSwapInterval(1);
gl.glEnable(GL.GL_DEPTH_TEST);
-
- final TextRenderer textRenderer = (TextRenderer) getRenderer();
-
- textRenderer.setAlpha(gl, 1.0f);
- textRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
+
+ final Renderer renderer = getRenderer();
+
+ renderer.setAlpha(gl, 1.0f);
+ renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
}
-
+
public void display(GLAutoDrawable drawable) {
super.display(drawable);
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 77f562dda..1f4a95511 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java
@@ -41,11 +41,12 @@ import org.junit.Test;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.curve.opengl.TextRenderer;
+import com.jogamp.graph.curve.opengl.TextRenderUtil;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontFactory;
-import com.jogamp.graph.geom.opengl.SVertex;
+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;
@@ -60,8 +61,9 @@ public class TestTextRendererNEWT10 extends UITestCase {
static boolean forceES2 = false;
static boolean forceGL3 = false;
static boolean mainRun = false;
-
- static final int[] texSize = new int[] { 0 };
+ static boolean useMSAA = true;
+
+ static final int[] texSize = new int[] { 0 };
static final int fontSize = 24;
static Font font;
@@ -69,19 +71,21 @@ public class TestTextRendererNEWT10 extends UITestCase {
public static void setup() throws IOException {
font = FontFactory.get(FontFactory.UBUNTU).getDefault();
}
-
+
static int atoi(String a) {
try {
return Integer.parseInt(a);
} catch (Exception ex) { throw new RuntimeException(ex); }
}
-
+
public static void main(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")) {
@@ -90,17 +94,26 @@ public class TestTextRendererNEWT10 extends UITestCase {
}
String tstname = TestTextRendererNEWT10.class.getName();
org.junit.runner.JUnitCore.main(tstname);
- }
-
+ }
+
static void sleep() {
try {
System.err.println("** new frame ** (sleep: "+duration+"ms)");
Thread.sleep(duration);
} catch (InterruptedException ie) {}
}
-
+
+ // @Test
+ public void test00TextRendererNONE01() throws InterruptedException {
+ testTextRendererImpl(0);
+ }
+
@Test
public void testTextRendererMSAA01() throws InterruptedException {
+ testTextRendererImpl(4);
+ }
+
+ void testTextRendererImpl(int sampleCount) throws InterruptedException {
final GLProfile glp;
if(forceGL3) {
glp = GLProfile.get(GLProfile.GL3);
@@ -110,75 +123,77 @@ public class TestTextRendererNEWT10 extends UITestCase {
glp = GLProfile.getGL2ES2();
}
final GLCapabilities caps = new GLCapabilities( glp );
- caps.setAlphaBits(4);
- caps.setSampleBuffers(true);
- caps.setNumSamples(4);
+ caps.setAlphaBits(4);
+ if( 0 < sampleCount ) {
+ caps.setSampleBuffers(true);
+ caps.setNumSamples(sampleCount);
+ }
System.err.println("Requested: "+caps);
final NEWTGLContext.WindowContext winctx = NEWTGLContext.createOnscreenWindow(caps, 800, 400, true);
final GLDrawable drawable = winctx.context.getGLDrawable();
final GL2ES2 gl = winctx.context.getGL().getGL2ES2();
- System.err.println(winctx.context);
Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
System.err.println("Chosen: "+winctx.window.getChosenCapabilities());
-
+
final RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
- final TextRenderer renderer = TextRenderer.create(rs, 0);
+ final RegionRenderer renderer = RegionRenderer.create(rs, 0);
+ final TextRenderUtil textRenderUtil = new TextRenderUtil(renderer);
// init
gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
renderer.init(gl);
renderer.setAlpha(gl, 1.0f);
- renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
+ renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
// reshape
- gl.glViewport(0, 0, drawable.getWidth(), drawable.getHeight());
+ gl.glViewport(0, 0, drawable.getWidth(), drawable.getHeight());
// renderer.reshapePerspective(gl, 45.0f, drawable.getWidth(), drawable.getHeight(), 0.1f, 1000.0f);
renderer.reshapeOrtho(gl, drawable.getWidth(), drawable.getHeight(), 0.1f, 1000.0f);
// display
- gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
- renderString(drawable, gl, renderer, "012345678901234567890123456789", 0, 0, -1000);
- renderString(drawable, gl, renderer, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, -1, -1000);
- renderString(drawable, gl, renderer, "Hello World", 0, -1, -1000);
- renderString(drawable, gl, renderer, "4567890123456", 4, -1, -1000);
- renderString(drawable, gl, renderer, "I like JogAmp", 4, -1, -1000);
-
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+ renderString(drawable, gl, textRenderUtil, "012345678901234567890123456789", 0, 0, -1000);
+ renderString(drawable, gl, textRenderUtil, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, -1, -1000);
+ renderString(drawable, gl, textRenderUtil, "Hello World", 0, -1, -1000);
+ renderString(drawable, gl, textRenderUtil, "4567890123456", 4, -1, -1000);
+ renderString(drawable, gl, textRenderUtil, "I like JogAmp", 4, -1, -1000);
+
int c = 0;
- renderString(drawable, gl, renderer, "GlueGen", c++, -1, -1000);
- renderString(drawable, gl, renderer, "JOAL", c++, -1, -1000);
- renderString(drawable, gl, renderer, "JOGL", c++, -1, -1000);
- renderString(drawable, gl, renderer, "JOCL", c++, -1, -1000);
-
+ renderString(drawable, gl, textRenderUtil, "GlueGen", c++, -1, -1000);
+ renderString(drawable, gl, textRenderUtil, "JOAL", c++, -1, -1000);
+ renderString(drawable, gl, textRenderUtil, "JOGL", c++, -1, -1000);
+ renderString(drawable, gl, textRenderUtil, "JOCL", c++, -1, -1000);
+
drawable.swapBuffers();
- sleep();
+ sleep();
// dispose
renderer.destroy(gl);
-
+
NEWTGLContext.destroyWindow(winctx);
- }
-
+ }
+
int lastRow = -1;
-
- void renderString(GLDrawable drawable, GL2ES2 gl, TextRenderer renderer, String text, int column, int row, int z0) {
+
+ void renderString(GLDrawable drawable, GL2ES2 gl, TextRenderUtil textRenderUtil, String text, int column, int row, int z0) {
final int height = drawable.getHeight();
-
+
int dx = 0;
- int dy = height;
+ int dy = height;
if(0>row) {
row = lastRow + 1;
}
AABBox textBox = font.getStringBounds(text, fontSize);
dx += font.getAdvanceWidth('X', fontSize) * column;
dy -= (int)textBox.getHeight() * ( row + 1 );
- renderer.resetModelview(null);
- renderer.translate(gl, dx, dy, z0);
- renderer.drawString3D(gl, font, text, fontSize, texSize);
-
+ textRenderUtil.renderer.resetModelview(null);
+ textRenderUtil.renderer.translate(gl, dx, dy, z0);
+ textRenderUtil.drawString3D(gl, font, text, fontSize, texSize);
+
lastRow = row;
- }
+ }
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java b/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java
index 38afed7fe..704e98999 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java
@@ -34,22 +34,23 @@ import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.fixedfunc.GLMatrixFunc;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.curve.opengl.TextRenderer;
+import com.jogamp.graph.curve.opengl.TextRenderUtil;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontFactory;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.opengl.math.geom.AABBox;
import com.jogamp.opengl.util.PMVMatrix;
import com.jogamp.opengl.util.glsl.ShaderState;
public abstract class TextRendererGLELBase implements GLEventListener {
+ public final Font font;
+ public final int usrRenderModes;
+
protected final int[] texSize = new int[] { 0 };
protected final float[] staticRGBAColor = new float[] { 1f, 1f, 1f, 1f };
- protected final Font font;
- protected final int usrRenderModes;
-
/**
* In exclusive mode, impl. uses a pixelScale of 1f and orthogonal PMV on window dimensions
* and renderString uses 'height' for '1'.
@@ -61,7 +62,8 @@ public abstract class TextRendererGLELBase implements GLEventListener {
protected boolean exclusivePMVMatrix = true;
protected PMVMatrix usrPMVMatrix = null;
protected RenderState rs = null;
- protected TextRenderer renderer = null;
+ protected RegionRenderer renderer = null;
+ protected TextRenderUtil textRenderUtil = null;
/** font size in pixels, default is 24 */
protected int fontSize = 24;
@@ -83,16 +85,25 @@ public abstract class TextRendererGLELBase implements GLEventListener {
this.font = _font;
}
}
+ public TextRendererGLELBase(final RenderState rs, final boolean exclusivePMVMatrix, final int renderModes) {
+ this(renderModes);
+ this.rs = rs;
+ this.exclusivePMVMatrix = exclusivePMVMatrix;
+ }
public void setFlipVerticalInGLOrientation(boolean v) { flipVerticalInGLOrientation=v; }
- public final TextRenderer getRenderer() { return renderer; }
+ public final RegionRenderer getRenderer() { return renderer; }
+ public final TextRenderUtil getTextRenderUtil() { return textRenderUtil; }
@Override
public void init(GLAutoDrawable drawable) {
if( null != font ) {
- exclusivePMVMatrix = null == usrPMVMatrix;
- this.rs = RenderState.createRenderState(new ShaderState(), SVertex.factory(), usrPMVMatrix);
- this.renderer = TextRenderer.create(rs, usrRenderModes);
+ if( null == this.rs ) {
+ exclusivePMVMatrix = null == usrPMVMatrix;
+ this.rs = RenderState.createRenderState(new ShaderState(), SVertex.factory(), usrPMVMatrix);
+ }
+ this.renderer = RegionRenderer.create(rs, usrRenderModes);
+ this.textRenderUtil = new TextRenderUtil(renderer);
if( 0 == usrRenderModes ) {
texSizeScale = 0;
}
@@ -103,7 +114,6 @@ public abstract class TextRendererGLELBase implements GLEventListener {
final ShaderState st = rs.getShaderState();
st.useProgram(gl, false);
} else {
- this.rs = null;
this.renderer = null;
}
}
@@ -181,7 +191,7 @@ public abstract class TextRendererGLELBase implements GLEventListener {
pmvMatrix.glScalef(pixelScale, pixelScale, 1f);
}
renderer.updateMatrix(gl);
- renderer.drawString3D(gl, font, text, fontSize, texSize);
+ textRenderUtil.drawString3D(gl, font, text, fontSize, texSize);
st.useProgram(gl, false);
gl.glDisable(GL2ES2.GL_BLEND);
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java
index 160dc0ffe..d4f07a163 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java
@@ -34,7 +34,7 @@ import javax.media.opengl.GLProfile;
import com.jogamp.graph.curve.Region;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.newt.event.KeyAdapter;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.WindowAdapter;
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java
index e7b5c73c5..068498980 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java
@@ -34,7 +34,7 @@ import javax.media.opengl.GLProfile;
import com.jogamp.graph.curve.Region;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.newt.event.KeyAdapter;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.WindowAdapter;
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java
index 4ebb937a0..4e3d271e1 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java
@@ -56,31 +56,32 @@ import com.jogamp.opengl.util.GLReadBufferUtil;
* Action Keys:
* - 1/2: zoom in/out
* - 6/7: 2nd pass texture size
- * - 0/9: rotate
+ * - 0/9: rotate
* - Q/W: change weight
* - v: toggle v-sync
* - s: screenshot
*/
public abstract class GPURendererListenerBase01 implements GLEventListener {
- private GLReadBufferUtil screenshot;
- private Renderer renderer;
- private int renderModes;
- private boolean debug;
- private boolean trace;
-
+ private final Renderer renderer;
+ private final int renderModes;
+ private final boolean debug;
+ private final boolean trace;
+
protected GLRegion region;
+ private final GLReadBufferUtil screenshot;
+
private KeyAction keyAction;
-
+
private volatile GLAutoDrawable autoDrawable = null;
-
+
private final float[] position = new float[] {0,0,0};
-
+
private float xTran = -10;
- private float yTran = 10;
+ private float yTran = 10;
private float ang = 0f;
private float zoom = -70f;
- private int[] texSize = new int[] { 400 };
+ private final int[] texSize = new int[] { 400 };
protected volatile float weight = 1.0f;
boolean ignoreInput = false;
@@ -92,7 +93,7 @@ public abstract class GPURendererListenerBase01 implements GLEventListener {
this.trace = trace;
this.screenshot = new GLReadBufferUtil(false, false);
}
-
+
public final Renderer getRenderer() { return renderer; }
public final int getRenderModes() { return renderModes; }
public final float getZoom() { return zoom; }
@@ -104,12 +105,12 @@ public abstract class GPURendererListenerBase01 implements GLEventListener {
public void setMatrix(float xtrans, float ytrans, float angle, int zoom, int fbosize) {
this.xTran = xtrans;
- this.yTran = ytrans;
- this.ang = angle;
+ this.yTran = ytrans;
+ this.ang = angle;
this.zoom = zoom;
- this.texSize[0] = fbosize;
+ this.texSize[0] = fbosize;
}
-
+
public void init(GLAutoDrawable drawable) {
autoDrawable = drawable;
GL2ES2 gl = drawable.getGL().getGL2ES2();
@@ -125,17 +126,17 @@ public abstract class GPURendererListenerBase01 implements GLEventListener {
gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
getRenderer().init(gl);
}
-
+
public void reshape(GLAutoDrawable drawable, int xstart, int ystart, int width, int height) {
GL2ES2 gl = drawable.getGL().getGL2ES2();
-
- gl.glViewport(xstart, ystart, width, height);
+
+ gl.glViewport(xstart, ystart, width, height);
renderer.reshapePerspective(gl, 45.0f, width, height, 0.1f, 7000.0f);
-
+
dumpMatrix();
- System.err.println("Reshape: "+renderer.getRenderState());
+ System.err.println("Reshape: "+renderer.getRenderState());
}
-
+
public void dispose(GLAutoDrawable drawable) {
autoDrawable = null;
GL2ES2 gl = drawable.getGL().getGL2ES2();
@@ -144,13 +145,13 @@ public abstract class GPURendererListenerBase01 implements GLEventListener {
}
screenshot.dispose(gl);
renderer.destroy(gl);
- }
-
+ }
+
public void zoom(int v){
zoom += v;
dumpMatrix();
}
-
+
public void move(float x, float y){
xTran += x;
yTran += y;
@@ -168,37 +169,37 @@ public abstract class GPURendererListenerBase01 implements GLEventListener {
weight += delta;
System.err.println("Global Weight: "+ weight);
}
-
+
void dumpMatrix() {
System.err.println("Matrix: " + xTran + "/" + yTran + " x"+zoom + " @"+ang);
}
-
- /** Attach the input listener to the window */
+
+ /** Attach the input listener to the window */
public void attachInputListenerTo(GLWindow window) {
if ( null == keyAction ) {
keyAction = new KeyAction();
- window.addKeyListener(keyAction);
+ window.addKeyListener(keyAction);
}
}
-
+
public void detachInputListenerFrom(GLWindow window) {
if ( null == keyAction ) {
return;
}
window.removeKeyListener(keyAction);
}
-
+
public void printScreen(GLAutoDrawable drawable, String dir, String tech, String objName, boolean exportAlpha) throws GLException, IOException {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
pw.printf("-%03dx%03d-Z%04d-T%04d-%s", drawable.getWidth(), drawable.getHeight(), (int)Math.abs(zoom), texSize[0], objName);
-
+
final String filename = dir + tech + sw +".png";
if(screenshot.readPixels(drawable.getGL(), false)) {
screenshot.write(new File(filename));
}
}
-
+
int screenshot_num = 0;
public void setIgnoreInput(boolean v) {
@@ -207,13 +208,13 @@ public abstract class GPURendererListenerBase01 implements GLEventListener {
public boolean getIgnoreInput() {
return ignoreInput;
}
-
+
public class KeyAction implements KeyListener {
public void keyPressed(KeyEvent arg0) {
if(ignoreInput) {
return;
}
-
+
if(arg0.getKeyCode() == KeyEvent.VK_1){
zoom(10);
}
@@ -239,13 +240,13 @@ public abstract class GPURendererListenerBase01 implements GLEventListener {
else if(arg0.getKeyCode() == KeyEvent.VK_7){
texSize[0] += 10;
System.err.println("Tex Size: " + texSize[0]);
- }
+ }
else if(arg0.getKeyCode() == KeyEvent.VK_0){
rotate(1);
}
else if(arg0.getKeyCode() == KeyEvent.VK_9){
rotate(-1);
- }
+ }
else if(arg0.getKeyCode() == KeyEvent.VK_Q){
editGlobalWeight(-0.1f);
}
@@ -257,7 +258,7 @@ public abstract class GPURendererListenerBase01 implements GLEventListener {
autoDrawable.invoke(false, new GLRunnable() {
public boolean run(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
- int i = gl.getSwapInterval();
+ int i = gl.getSwapInterval();
i = i==0 ? 1 : 0;
gl.setSwapInterval(i);
final GLAnimatorControl a = drawable.getAnimator();
@@ -271,7 +272,7 @@ public abstract class GPURendererListenerBase01 implements GLEventListener {
return true;
}
});
- }
+ }
}
else if(arg0.getKeyCode() == KeyEvent.VK_S){
rotate(-1);
@@ -279,19 +280,19 @@ public abstract class GPURendererListenerBase01 implements GLEventListener {
autoDrawable.invoke(false, new GLRunnable() {
public boolean run(GLAutoDrawable drawable) {
try {
- final String type = Region.isVBAA(renderModes) ? "vbaa0-msaa1" : "vbaa1-msaa0" + ( Region.isNonUniformWeight(renderModes) ? "-vc" : "-uc" ) ;
+ final String type = Region.isVBAA(renderModes) ? "vbaa0-msaa1" : "vbaa1-msaa0" + ( Region.isNonUniformWeight(renderModes) ? "-vc" : "-uc" ) ;
printScreen(drawable, "./", "demo-"+type, "snap"+screenshot_num, false);
screenshot_num++;
} catch (GLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
- }
+ }
return true;
}
});
- }
- }
+ }
+ }
}
public void keyReleased(KeyEvent arg0) {}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextGLListener0A.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextGLListener0A.java
index 5c7d15ad1..4d544019c 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextGLListener0A.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextGLListener0A.java
@@ -32,40 +32,40 @@ import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLAutoDrawable;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.curve.opengl.TextRenderer;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.curve.opengl.Renderer;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.util.glsl.ShaderState;
public class GPUTextGLListener0A extends GPUTextRendererListenerBase01 {
-
+
public GPUTextGLListener0A() {
this( RenderState.createRenderState(new ShaderState(), SVertex.factory()), 0, 0, false, false ) ;
}
-
+
public GPUTextGLListener0A(RenderState rs, int numpass, int fbosize, boolean debug, boolean trace) {
super(rs, numpass, debug, trace);
- setMatrix(-400, -30, 0f, -500, fbosize);
+ setMatrix(-400, -30, 0f, -500, fbosize);
}
-
+
public void init(GLAutoDrawable drawable) {
if(drawable instanceof GLWindow) {
final GLWindow glw = (GLWindow) drawable;
attachInputListenerTo(glw);
- }
+ }
super.init(drawable);
-
+
GL2ES2 gl = drawable.getGL().getGL2ES2();
-
- final TextRenderer textRenderer = (TextRenderer) getRenderer();
-
+
+ final Renderer renderer = getRenderer();
+
gl.setSwapInterval(1);
gl.glEnable(GL2ES2.GL_DEPTH_TEST);
gl.glEnable(GL2ES2.GL_BLEND);
- textRenderer.setAlpha(gl, 1.0f);
- textRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
+ renderer.setAlpha(gl, 1.0f);
+ renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
}
-
+
public void dispose(GLAutoDrawable drawable) {
if(drawable instanceof GLWindow) {
final GLWindow glw = (GLWindow) drawable;
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java
index d257f78fc..c58d10254 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java
@@ -32,10 +32,9 @@ import javax.media.opengl.FPSCounter;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
-
import com.jogamp.graph.curve.opengl.GLRegion;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.newt.event.KeyAdapter;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.WindowAdapter;
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java
index 1b71cd781..59d235537 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java
@@ -33,7 +33,7 @@ import javax.media.opengl.GLProfile;
import com.jogamp.graph.curve.Region;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.newt.event.KeyAdapter;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.WindowAdapter;
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java
index 2ab0632d3..d90b4f849 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java
@@ -35,8 +35,10 @@ import javax.media.opengl.GLAnimatorControl;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLException;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.curve.opengl.TextRenderer;
+import com.jogamp.graph.curve.opengl.Renderer;
+import com.jogamp.graph.curve.opengl.TextRenderUtil;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontFactory;
import com.jogamp.newt.event.KeyEvent;
@@ -52,7 +54,7 @@ import com.jogamp.opengl.math.geom.AABBox;
* - 0/9: rotate
* - v: toggle v-sync
* - s: screenshot
- *
+ *
* Additional Keys:
* - 3/4: font +/-
* - h: toogle draw 'font set'
@@ -61,9 +63,10 @@ import com.jogamp.opengl.math.geom.AABBox;
* - i: live input text input (CR ends it, backspace supported)
*/
public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerBase01 {
+ public final TextRenderUtil textRenderUtil;
int fontSet = FontFactory.UBUNTU;
Font font;
-
+
int headType = 0;
boolean drawFPS = false;
final int fontSizeFixed = 6;
@@ -73,10 +76,10 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
AABBox fontNameBox;
String headtext;
AABBox headbox;
-
+
static final String text1 = "abcdefghijklmnopqrstuvwxyz\nABCDEFGHIJKLMNOPQRSTUVWXYZ\n0123456789.:,;(*!?/\\\")$%^&-+@~#<>{}[]";
static final String text2 = "The quick brown fox jumps over the lazy dog";
- static final String textX =
+ static final String textX =
"JOGAMP graph demo using Resolution Independent NURBS\n"+
"JOGAMP JOGL - OpenGL ES2 profile\n"+
"Press 1/2 to zoom in/out the below text\n"+
@@ -84,30 +87,31 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
"Press 0/9 to rotate the below string\n"+
"Press v to toggle vsync\n"+
"Press i for live input text input (CR ends it, backspace supported)\n"+
- "Press f to toggle fps. H for different text, space for font type\n";
-
- static final String textX2 =
+ "Press f to toggle fps. H for different text, space for font type\n";
+
+ 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"+
+ "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";
-
+ "-------Press H to change text---------\n";
+
StringBuilder userString = new StringBuilder();
boolean userInput = false;
-
- public GPUTextRendererListenerBase01(RenderState rs, int modes, boolean debug, boolean trace) {
- super(TextRenderer.create(rs, modes), modes, debug, trace);
+
+ public GPUTextRendererListenerBase01(RenderState rs, int renderModes, boolean debug, boolean trace) {
+ super(RegionRenderer.create(rs, renderModes), renderModes, debug, trace);
+ this.textRenderUtil = new TextRenderUtil(this.getRenderer());
try {
this.font = FontFactory.get(fontSet).getDefault();
dumpFontNames();
-
+
this.fontName = font.toString();
this.fontNameBox = font.getStringBounds(fontName, fontSizeFixed*2);
- switchHeadBox();
+ switchHeadBox();
} catch (IOException ioe) {
System.err.println("Catched: "+ioe.getMessage());
ioe.printStackTrace();
@@ -117,25 +121,25 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
void dumpFontNames() {
System.err.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.err.println(font.getAllNames(null, "\n"));
- System.err.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
+ System.err.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
}
-
+
void switchHeadBox() {
- headType = ( headType + 1 ) % 4 ;
+ headType = ( headType + 1 ) % 4 ;
switch(headType) {
case 0:
headtext = null;
break;
-
+
case 1:
headtext= textX2;
break;
case 2:
headtext= textX;
break;
-
+
default:
- headtext = text1;
+ headtext = text1;
}
if(null != headtext) {
headbox = font.getStringBounds(headtext, fontSizeFixed*3);
@@ -146,60 +150,60 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
final int width = drawable.getWidth();
final int height = drawable.getHeight();
GL2ES2 gl = drawable.getGL().getGL2ES2();
-
+
gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Demo02 needs to have this set here as well .. hmm ?
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
- final TextRenderer textRenderer = (TextRenderer) getRenderer();
- textRenderer.reshapeOrtho(null, width, height, 0.1f, 7000.0f);
- textRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
+ final Renderer renderer = getRenderer();
+ renderer.reshapeOrtho(null, width, height, 0.1f, 7000.0f);
+ renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
final GLAnimatorControl animator = drawable.getAnimator();
final boolean _drawFPS = drawFPS && null != animator && animator.getTotalFPSFrames()>10;
-
+
if(_drawFPS) {
final float fps = animator.getTotalFPS();
final String fpsS = String.valueOf(fps);
final int fpsSp = fpsS.indexOf('.');
- textRenderer.resetModelview(null);
- textRenderer.translate(gl, fontSizeFixed, fontSizeFixed, -6000);
- textRenderer.drawString3D(gl, font, fpsS.substring(0, fpsSp+2)+" fps", fontSizeFixed*3, getTexSize());
+ renderer.resetModelview(null);
+ renderer.translate(gl, fontSizeFixed, fontSizeFixed, -6000);
+ textRenderUtil.drawString3D(gl, font, fpsS.substring(0, fpsSp+2)+" fps", fontSizeFixed*3, getTexSize());
}
-
+
int dx = width-(int)fontNameBox.getWidth()-2 ;
- int dy = height - 10;
-
- textRenderer.resetModelview(null);
- textRenderer.translate(gl, dx, dy, -6000);
- textRenderer.drawString3D(gl, font, fontName, fontSizeFixed*2, getTexSize());
-
+ int dy = height - 10;
+
+ renderer.resetModelview(null);
+ renderer.translate(gl, dx, dy, -6000);
+ textRenderUtil.drawString3D(gl, font, fontName, fontSizeFixed*2, getTexSize());
+
dx = 10;
dy += -(int)fontNameBox.getHeight() - 10;
-
- if(null != headtext) {
- textRenderer.resetModelview(null);
- textRenderer.translate(gl, dx, dy, -6000);
- textRenderer.drawString3D(gl, font, headtext, fontSizeFixed*3, getTexSize());
+
+ if(null != headtext) {
+ renderer.resetModelview(null);
+ renderer.translate(gl, dx, dy, -6000);
+ textRenderUtil.drawString3D(gl, font, headtext, fontSizeFixed*3, getTexSize());
}
-
- textRenderer.reshapePerspective(null, 45.0f, width, height, 0.1f, 7000.0f);
- textRenderer.resetModelview(null);
- textRenderer.translate(null, getXTran(), getYTran(), getZoom());
- textRenderer.rotate(gl, getAngle(), 0, 1, 0);
- textRenderer.setColorStatic(gl, 1.0f, 0.0f, 0.0f);
+ renderer.reshapePerspective(null, 45.0f, width, height, 0.1f, 7000.0f);
+
+ renderer.resetModelview(null);
+ renderer.translate(null, getXTran(), getYTran(), getZoom());
+ renderer.rotate(gl, getAngle(), 0, 1, 0);
+ renderer.setColorStatic(gl, 1.0f, 0.0f, 0.0f);
if(!userInput) {
- textRenderer.drawString3D(gl, font, text2, fontSize, getTexSize());
+ textRenderUtil.drawString3D(gl, font, text2, fontSize, getTexSize());
} else {
- textRenderer.drawString3D(gl, font, userString.toString(), fontSize, getTexSize());
+ textRenderUtil.drawString3D(gl, font, userString.toString(), fontSize, getTexSize());
}
- }
-
+ }
+
public void fontIncr(int v) {
fontSize = Math.abs((fontSize + v) % fontSizeModulo) ;
dumpMatrix(true);
}
- public boolean nextFontSet() {
+ public boolean nextFontSet() {
try {
int set = ( fontSet == FontFactory.UBUNTU ) ? FontFactory.JAVA : FontFactory.UBUNTU ;
Font _font = FontFactory.get(set).getDefault();
@@ -207,7 +211,7 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
fontSet = set;
font = _font;
fontName = font.getFullFamilyName(null).toString();
- fontNameBox = font.getStringBounds(fontName, fontSizeFixed*3);
+ fontNameBox = font.getStringBounds(fontName, fontSizeFixed*3);
dumpFontNames();
return true;
}
@@ -216,7 +220,7 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
}
return false;
}
-
+
public boolean setFontSet(int set, int family, int stylebits) {
try {
Font _font = FontFactory.get(set).get(family, stylebits);
@@ -224,7 +228,7 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
fontSet = set;
font = _font;
fontName = font.getFullFamilyName(null).toString();
- fontNameBox = font.getStringBounds(fontName, fontSizeFixed*3);
+ fontNameBox = font.getStringBounds(fontName, fontSizeFixed*3);
dumpFontNames();
return true;
}
@@ -233,25 +237,25 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
}
return false;
}
-
+
public boolean isUserInputMode() { return userInput; }
-
+
void dumpMatrix(boolean bbox) {
System.err.println("Matrix: " + getXTran() + "/" + getYTran() + " x"+getZoom() + " @"+getAngle() +" fontSize "+fontSize);
if(bbox) {
System.err.println("bbox: "+font.getStringBounds(text2, fontSize));
}
}
-
+
KeyAction keyAction = null;
-
+
@Override
public void attachInputListenerTo(GLWindow window) {
if ( null == keyAction ) {
keyAction = new KeyAction();
window.addKeyListener(keyAction);
- super.attachInputListenerTo(window);
- }
+ super.attachInputListenerTo(window);
+ }
}
@Override
@@ -262,18 +266,18 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
}
window.removeKeyListener(keyAction);
}
-
+
public void printScreen(GLAutoDrawable drawable, String dir, String tech, boolean exportAlpha) throws GLException, IOException {
- final String fn = font.getFullFamilyName(null).toString();
+ final String fn = font.getFullFamilyName(null).toString();
printScreen(drawable, dir, tech, fn.replace(' ', '_'), exportAlpha);
}
-
+
public class KeyAction implements KeyListener {
public void keyPressed(KeyEvent e) {
if(userInput) {
return;
}
- final short s = e.getKeySymbol();
+ final short s = e.getKeySymbol();
if(s == KeyEvent.VK_3) {
fontIncr(10);
}
@@ -282,11 +286,11 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
}
else if(s == KeyEvent.VK_H) {
switchHeadBox();
- }
+ }
else if(s == KeyEvent.VK_F) {
- drawFPS = !drawFPS;
- }
- else if(s == KeyEvent.VK_SPACE) {
+ drawFPS = !drawFPS;
+ }
+ else if(s == KeyEvent.VK_SPACE) {
nextFontSet();
}
else if(s == KeyEvent.VK_I) {
@@ -294,12 +298,12 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
setIgnoreInput(true);
}
}
-
+
public void keyReleased(KeyEvent e) {
if( !e.isPrintableKey() || e.isAutoRepeat() ) {
return;
- }
- if(userInput) {
+ }
+ if(userInput) {
final short k = e.getKeySymbol();
if( KeyEvent.VK_ENTER == k ) {
userInput = false;
@@ -308,7 +312,7 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
userString.deleteCharAt(userString.length()-1);
} else {
final char c = e.getKeyChar();
- if( font.isPrintableChar( c ) ) {
+ if( font.isPrintableChar( c ) ) {
userString.append(c);
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java
index c9a3f5542..c9f27df80 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java
@@ -15,7 +15,7 @@ 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.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.newt.event.MouseAdapter;
import com.jogamp.newt.event.MouseEvent;
import com.jogamp.newt.opengl.GLWindow;
@@ -28,59 +28,59 @@ import com.jogamp.opengl.util.glsl.ShaderState;
public class GPUUISceneGLListener0A implements GLEventListener {
private boolean debug = false;
- private boolean trace = false;
-
+ private boolean trace = false;
+
private final int renderModes;
- private final int[] texSize = new int[1];
+ private final int[] texSize = new int[1];
private final int renderModes2;
- private final int[] texSize2 = new int[1];
+ private final int[] texSize2 = new int[1];
private RegionRenderer regionRenderer;
- private RenderState rs;
-
+ private final RenderState rs;
+
int fontSet = FontFactory.UBUNTU;
Font font;
final int fontSizeFixed = 6;
-
+
private float xTran = 0;
- private float yTran = 0;
+ private float yTran = 0;
private float ang = 0f;
private float zoom = -200f;
- private float zoomText = 1f;
+ private final float zoomText = 1f;
private int currentText = 0;
-
+
private Label[] labels = null;
private String[] strings = null;
- private UIRegion[] labelRegions;
+ private final UIRegion[] labelRegions;
private UIRegion fpsRegion = null;
private UIRegion jogampRegion = null;
private RIButton[] buttons = null;
-
- private int numSelectable = 6;
-
+
+ private final int numSelectable = 6;
+
private SceneUIController sceneUIController = null;
private MultiTouchListener multiTouchListener = null;
private boolean showFPS = false;
private GLAutoDrawable cDrawable;
- private float fps = 0;
-
- private String jogamp = "JogAmp - Jogl Graph Module Demo";
- private float angText = 0;
-
+ private float fps = 0;
+
+ private final String jogamp = "JogAmp - Jogl Graph Module Demo";
+ private final float angText = 0;
+
public GPUUISceneGLListener0A() {
this(0);
}
-
+
public GPUUISceneGLListener0A(int renderModes) {
this(RenderState.createRenderState(new ShaderState(), SVertex.factory()), renderModes, false, false);
}
-
+
public GPUUISceneGLListener0A(RenderState rs, int renderModes, boolean debug, boolean trace) {
this.rs = rs;
this.renderModes = renderModes;
this.texSize[0] = Region.isVBAA(renderModes) ? 400 : 0;
this.renderModes2 = 0;
this.texSize2[0] = 0;
-
+
this.debug = debug;
this.trace = trace;
try {
@@ -92,16 +92,16 @@ public class GPUUISceneGLListener0A implements GLEventListener {
labelRegions = new UIRegion[3];
sceneUIController = new SceneUIController();
}
-
+
private void initButtons(int width, int height) {
buttons = new RIButton[numSelectable];
int xaxis = -110;
float xSize = 40f;
float ySize = 16f;
-
+
int start = 50;
int diff = (int)ySize + 5;
-
+
buttons[0] = new RIButton(SVertex.factory(), font, "Next Text", xSize, ySize){
public void onClick() {
currentText = (currentText+1)%3;
@@ -109,9 +109,9 @@ public class GPUUISceneGLListener0A implements GLEventListener {
public void onPressed() { }
public void onRelease() { }
};
-
+
buttons[0].setPosition(xaxis,start,0);
-
+
buttons[1] = new RIButton(SVertex.factory(), font, "Show FPS", xSize, ySize){
public void onClick() {
final GLAnimatorControl a = cDrawable.getAnimator();
@@ -125,7 +125,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
};
buttons[1].setPosition(xaxis,start - diff,0);
buttons[1].setToggleable(true);
-
+
buttons[2] = new RIButton(SVertex.factory(), font, "v-sync", xSize, ySize){
public void onClick() {
cDrawable.invoke(false, new GLRunnable() {
@@ -145,18 +145,18 @@ public class GPUUISceneGLListener0A implements GLEventListener {
};
buttons[2].setPosition(xaxis,start-diff*2,0);
buttons[2].setToggleable(true);
-
+
buttons[3] = new RIButton(SVertex.factory(), font, "Tilt +Y", xSize, ySize) {
- public void onClick() {
+ public void onClick() {
ang+=10;
}
- public void onPressed() {
+ public void onPressed() {
}
public void onRelease() { }
};
buttons[3].setPosition(xaxis,start-diff*3,0);
-
+
buttons[4] = new RIButton(SVertex.factory(), font, "Tilt -Y", xSize, ySize){
public void onClick() {
ang-=10;
@@ -165,7 +165,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
public void onRelease() { }
};
buttons[4].setPosition(xaxis,start-diff*4,0);
-
+
buttons[5] = new RIButton(SVertex.factory(), font, "Quit", xSize, ySize){
public void onClick() {
cDrawable.destroy();
@@ -176,26 +176,26 @@ public class GPUUISceneGLListener0A implements GLEventListener {
buttons[5].setPosition(xaxis,start-diff*5,0);
buttons[5].setButtonColor(0.8f, 0.0f, 0.0f);
buttons[5].setLabelColor(1.0f, 1.0f, 1.0f);
-
+
buttons[5].setButtonSelectedColor(0.8f, 0.8f, 0.8f);
buttons[5].setLabelSelectedColor(0.8f, 0.0f, 0.0f);
}
-
+
private void initTexts() {
strings = new String[3];
-
+
strings[0] = "abcdefghijklmn\nopqrstuvwxyz\nABCDEFGHIJKL\nMNOPQRSTUVWXYZ\n0123456789.:,;(*!?/\\\")$%^&-+@~#<>{}[]";
strings[1] = "The quick brown fox\njumps over the lazy\ndog";
-
- strings[2] =
+
+ strings[2] =
"Lorem ipsum dolor sit amet, consectetur\n"+
"Ut purus odio, rhoncus sit amet com\n"+
"quam iaculis urna cursus ornare. Nullam\n"+
- "In hac habitasse platea dictumst. Vivam\n"+
+ "In hac habitasse platea dictumst. Vivam\n"+
"Morbi quis bibendum nibh. Donec lectus\n"+
"Donec ut dolor et nulla tristique variu\n"+
"in lorem. Maecenas in ipsum ac justo sc\n";
-
+
labels = new Label[3];
}
@@ -205,7 +205,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
final GLWindow glw = (GLWindow) drawable;
attachInputListenerTo(glw);
} else {
- System.err.println("GPUUISceneGLListener0A: init (0)");
+ System.err.println("GPUUISceneGLListener0A: init (0)");
}
final int width = drawable.getWidth();
final int height = drawable.getHeight();
@@ -217,26 +217,26 @@ public class GPUUISceneGLListener0A implements GLEventListener {
if(trace) {
gl = gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", null, gl, new Object[] { System.err } ) ).getGL2ES2();
}
-
+
try {
font = FontFactory.get(fontSet).getDefault();
} catch (IOException ioe) {
System.err.println("Catched: "+ioe.getMessage());
ioe.printStackTrace();
}
-
- regionRenderer = RegionRenderer.create(rs, renderModes);
-
+
+ regionRenderer = RegionRenderer.create(rs, renderModes);
+
gl.glEnable(GL2ES2.GL_DEPTH_TEST);
gl.glEnable(GL2ES2.GL_BLEND);
-
+
regionRenderer.init(gl);
regionRenderer.setAlpha(gl, 1.0f);
regionRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
-
+
initTexts();
initButtons(width, height);
-
+
sceneUIController.setRenderer(regionRenderer, rs, renderModes, texSize);
sceneUIController.addShape(buttons[0]);
sceneUIController.addShape(buttons[1]);
@@ -245,18 +245,18 @@ public class GPUUISceneGLListener0A implements GLEventListener {
sceneUIController.addShape(buttons[4]);
sceneUIController.addShape(buttons[5]);
drawable.addGLEventListener(sceneUIController);
-
+
Label jlabel = new Label(SVertex.factory(), font, fontSizeFixed, jogamp){
public void onClick() { }
public void onPressed() { }
public void onRelease() { }
};
-
+
jogampRegion = new UIRegion(jlabel);
final GLAnimatorControl a = drawable.getAnimator();
if( null != a ) {
a.resetFPSCounter();
- }
+ }
}
public void dispose(GLAutoDrawable drawable) {
@@ -265,11 +265,11 @@ public class GPUUISceneGLListener0A implements GLEventListener {
final GLWindow glw = (GLWindow) drawable;
detachInputListenerFrom(glw);
} else {
- System.err.println("GPUUISceneGLListener0A: dispose (0)");
+ System.err.println("GPUUISceneGLListener0A: dispose (0)");
}
// sceneUIController will remove itself from the drawable!
-
+
GL2ES2 gl = drawable.getGL().getGL2ES2();
regionRenderer.destroy(gl);
}
@@ -279,20 +279,20 @@ public class GPUUISceneGLListener0A implements GLEventListener {
final int width = drawable.getWidth();
final int height = drawable.getHeight();
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);
-
+
regionRenderer.reshapePerspective(null, 45.0f, width, height, 0.1f, 7000.0f);
sceneUIController.setTranslate(xTran, yTran, zoom);
sceneUIController.setRotation(0, ang, 0);
-
+
renderScene(drawable);
}
-
+
private void renderScene(GLAutoDrawable drawable) {
GL2ES2 gl = drawable.getGL().getGL2ES2();
-
+
regionRenderer.resetModelview(null);
regionRenderer.translate(null, xTran-50, yTran+43, zoom);
regionRenderer.translate(gl, 0, 30, 0);
@@ -300,8 +300,8 @@ public class GPUUISceneGLListener0A implements GLEventListener {
regionRenderer.scale(gl, 1.5f, 1.5f, 1.0f);
regionRenderer.rotate(gl, angText , 0, 1, 0);
regionRenderer.setColorStatic(gl, 0.0f, 1.0f, 0.0f);
- regionRenderer.draw(gl, jogampRegion.getRegion(gl, rs, 0), null);
-
+ regionRenderer.draw(gl, jogampRegion.getRegion(gl, regionRenderer, 0), null);
+
if(null == labelRegions[currentText]) {
if( null == labels[currentText]) {
labels[currentText] = new Label(SVertex.factory(), font, fontSizeFixed, strings[currentText]){
@@ -312,20 +312,20 @@ public class GPUUISceneGLListener0A implements GLEventListener {
}
labelRegions[currentText] = new UIRegion(labels[currentText]);
}
-
+
regionRenderer.resetModelview(null);
regionRenderer.translate(null, xTran-50, yTran, zoom);
regionRenderer.translate(gl, 0, 30, 0);
regionRenderer.scale(null, zoomText, zoomText, 1);
regionRenderer.scale(gl, 1.5f, 1.5f, 1.0f);
regionRenderer.rotate(gl, zoomText, 0, 1, 0);
-
+
regionRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
- regionRenderer.draw(gl, labelRegions[currentText].getRegion(gl, rs, renderModes2), texSize2);
-
+ regionRenderer.draw(gl, labelRegions[currentText].getRegion(gl, regionRenderer, renderModes2), texSize2);
+
final GLAnimatorControl animator = drawable.getAnimator();
final boolean _drawFPS = showFPS && null != animator;
-
+
if(_drawFPS && fps != animator.getTotalFPS()) {
if(null != fpsRegion) {
fpsRegion.destroy(gl, rs);
@@ -333,26 +333,26 @@ public class GPUUISceneGLListener0A implements GLEventListener {
fps = animator.getTotalFPS();
final String fpsS = String.valueOf(fps);
final int fpsSp = fpsS.indexOf('.');
-
+
Label fpsLabel = new Label(SVertex.factory(), font, fontSizeFixed, fpsS.substring(0, fpsSp+2)+" fps"){
public void onClick() { }
public void onPressed() { }
public void onRelease() { }
};
fpsRegion = new UIRegion(fpsLabel);
- }
+ }
if(showFPS && null != fpsRegion) {
regionRenderer.translate(gl, 0, -60, 0);
regionRenderer.scale(null, zoomText, zoomText, 1);
- regionRenderer.draw(gl, fpsRegion.getRegion(gl, rs, 0), null);
+ regionRenderer.draw(gl, fpsRegion.getRegion(gl, regionRenderer, 0), null);
}
}
-
+
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
System.err.println("GPUUISceneGLListener0A: reshape");
GL2ES2 gl = drawable.getGL().getGL2ES2();
-
- gl.glViewport(x, y, width, height);
+
+ gl.glViewport(x, y, width, height);
regionRenderer.reshapePerspective(gl, 45.0f, width, height, 5f, 70.0f);
}
@@ -363,23 +363,23 @@ public class GPUUISceneGLListener0A implements GLEventListener {
sceneUIController.attachInputListenerTo(window);
}
}
-
+
public void detachInputListenerFrom(GLWindow window) {
if ( null != multiTouchListener ) {
window.removeMouseListener(multiTouchListener);
sceneUIController.detachInputListenerFrom(window);
}
}
-
+
private class MultiTouchListener extends MouseAdapter {
int lx = 0;
int ly = 0;
-
+
boolean first = false;
-
+
@Override
public void mousePressed(MouseEvent e) {
- first = true;
+ first = true;
}
@Override
@@ -399,9 +399,9 @@ public class GPUUISceneGLListener0A implements GLEventListener {
}
int nv = Math.abs(e.getY(0)-e.getY(1));
int dy = nv - lx;
-
+
zoom += 2 * Math.signum(dy);
-
+
lx = nv;
} else {
// 1 pointer drag
@@ -413,7 +413,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
}
int nx = e.getX();
int ny = e.getY();
- int dx = nx - lx;
+ int dx = nx - lx;
int dy = ny - ly;
if(Math.abs(dx) > Math.abs(dy)){
xTran += Math.signum(dx);
@@ -425,7 +425,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
ly = ny;
}
}
-
+
@Override
public void mouseWheelMoved(MouseEvent e) {
if( !e.isShiftDown() ) {
@@ -433,4 +433,4 @@ public class GPUUISceneGLListener0A implements GLEventListener {
}
}
}
-} \ No newline at end of file
+} \ No newline at end of file
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java
index 0563ab2cf..17b9642d9 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java
@@ -4,7 +4,7 @@ import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.newt.event.WindowAdapter;
import com.jogamp.newt.event.WindowEvent;
import com.jogamp.newt.opengl.GLWindow;
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo02.java
index 4c8da139e..a4673f0c5 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo02.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo02.java
@@ -5,7 +5,7 @@ import javax.media.opengl.GLProfile;
import com.jogamp.graph.curve.Region;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.newt.event.WindowAdapter;
import com.jogamp.newt.event.WindowEvent;
import com.jogamp.newt.opengl.GLWindow;
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java
index 4fef2d8c2..baaae3521 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java
@@ -27,12 +27,15 @@
*/
package com.jogamp.opengl.test.junit.graph.demos.ui;
-import javax.media.opengl.GL2ES2;
+import java.util.HashMap;
-import jogamp.graph.curve.text.GlyphString;
+import javax.media.opengl.GL2ES2;
+import com.jogamp.graph.curve.OutlineShape;
+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.curve.opengl.Renderer;
+import com.jogamp.graph.curve.opengl.TextRenderUtil;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.geom.Vertex.Factory;
@@ -41,35 +44,36 @@ public abstract class Label extends UIShape implements UITextShape {
protected Font font;
protected int size;
protected String text;
- protected GlyphString glyphString;
-
+ protected GLRegion glyphRegion;
+
public Label(Factory<? extends Vertex> factory, Font font, int size, String text) {
super(factory);
this.font = font;
this.size = size;
this.text = text;
}
-
- public GlyphString getGlyphString() {
- return glyphString;
+
+ @Override
+ public GLRegion getRegion() {
+ return glyphRegion;
}
-
+
public String getText() {
return text;
}
-
+
public void setText(String text) {
this.text = text;
dirty |= DIRTY_SHAPE;
}
-
+
public Font getFont() {
return font;
}
public void setFont(Font font) {
this.font = font;
- dirty |= DIRTY_SHAPE;
+ dirty |= DIRTY_SHAPE;
}
public int getSize() {
@@ -78,28 +82,29 @@ public abstract class Label extends UIShape implements UITextShape {
public void setSize(int size) {
this.size = size;
- dirty |= DIRTY_SHAPE;
+ dirty |= DIRTY_SHAPE;
}
+ @Override
public String toString(){
return "Label [" + font.toString() + ", size " + size + ", " + getText() + "]";
}
@Override
- protected void clearImpl() {
- if(null != glyphString) {
- glyphString.destroy(null, null);
- }
+ protected void clearImpl(GL2ES2 gl, Renderer renderer) {
+ if(null != glyphRegion) {
+ glyphRegion.destroy(gl, renderer.getRenderState());
+ }
}
-
+
@Override
- protected void createShape() {
- clearImpl();
- glyphString = GlyphString.createString(shape, getVertexFactory(), font, size, text);
+ protected void createShape(Renderer renderer) {
+ clearImpl(null, null);
+ glyphRegion = TextRenderUtil.createRegion(renderer.getRenderModes(), renderer.getRenderState().getVertexFactory(),
+ font, text, size);
}
@Override
- public void render(GL2ES2 gl, RenderState rs, RegionRenderer renderer,
- int renderModes, int[/*1*/] texSize, boolean selection) {
+ public void render(GL2ES2 gl, RegionRenderer renderer, int renderModes, int[/*1*/] texSize, boolean selection) {
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java
index 3060c5657..d291c903a 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java
@@ -30,7 +30,7 @@ package com.jogamp.opengl.test.junit.graph.demos.ui;
import javax.media.opengl.GL2ES2;
import com.jogamp.graph.curve.opengl.RegionRenderer;
-import com.jogamp.graph.curve.opengl.RenderState;
+import com.jogamp.graph.curve.opengl.Renderer;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.geom.Vertex.Factory;
@@ -41,20 +41,20 @@ import com.jogamp.opengl.test.junit.graph.demos.ui.opengl.UIRegion;
*/
public abstract class RIButton extends UIShape {
private float width, height;
- private Label label;
+ private final Label label;
private float spacing = 4.0f;
private float corner = 1.0f;
private float labelZOffset = -0.05f;
-
+
private float[] buttonColor = {0.6f, 0.6f, 0.6f};
private float[] buttonSelectedColor = {0.8f,0.8f,0.8f};
private float[] labelColor = {1.0f, 1.0f, 1.0f};
private float[] labelSelectedColor = {0.1f, 0.1f, 0.1f};
-
-
+
+
public RIButton(Factory<? extends Vertex> factory, Font labelFont, String labelText, float width, float height) {
super(factory);
-
+
// FIXME: Determine font size - PMV Matrix relation ?
// this.label = new Label(factory, labelFont, (int)(height - 2f * spacing), labelText);
this.label = new Label(factory, labelFont, 10, labelText){
@@ -62,7 +62,7 @@ public abstract class RIButton extends UIShape {
public void onPressed() { }
public void onRelease() { }
};
-
+
this.width = width;
this.height = height;
}
@@ -77,20 +77,20 @@ public abstract class RIButton extends UIShape {
this.height = height;
dirty |= DIRTY_SHAPE;
}
-
+
@Override
- protected void clearImpl() {
+ protected void clearImpl(GL2ES2 gl, Renderer renderer) {
label.clear();
}
-
+
@Override
- protected void createShape() {
- // FIXME: Only possible if all data (color) is
+ protected void createShape(Renderer renderer) {
+ // FIXME: Only possible if all data (color) is
// is incl. in Outline Shape.
// Until then - draw each separately!
//shape.addOutlinShape( label.getShape() );
label.updateShape();
-
+
final AABBox lbox = label.getBounds();
if(corner == 0.0f) {
createSharpOutline(lbox);
@@ -99,33 +99,33 @@ public abstract class RIButton extends UIShape {
}
float sx = getWidth() / ( 2f*spacing + lbox.getWidth() );
float sy = getHeight() / ( 2f*spacing + lbox.getHeight() );
-
+
setScale(sx, sy, 1);
}
-
-
+
+
private void createSharpOutline(AABBox lbox) {
float th = (2f*spacing) + lbox.getHeight();
float tw = (2f*spacing) + lbox.getWidth();
-
+
float minX = lbox.getMinX()-spacing;
float minY = lbox.getMinY()-spacing;
float minZ = labelZOffset;
-
+
shape.addVertex(minX, minY, minZ, true);
shape.addVertex(minX+tw, minY, minZ, true);
shape.addVertex(minX+tw, minY + th, minZ, true);
shape.addVertex(minX, minY + th, minZ, true);
shape.closeLastOutline();
}
-
+
private void createCurvedOutline(AABBox lbox){
float th = 2.0f*spacing + lbox.getHeight();
float tw = 2.0f*spacing + lbox.getWidth();
-
+
float cw = 0.5f*corner*Math.min(tw, th);
float ch = 0.5f*corner*Math.min(tw, th);
-
+
float minX = lbox.getMinX()-spacing;
float minY = lbox.getMinY()-spacing;
float minZ = labelZOffset;
@@ -143,7 +143,7 @@ public abstract class RIButton extends UIShape {
shape.addVertex(minX, minY + th - ch, minZ, true);
shape.closeLastOutline();
}
-
+
public void setCorner(float corner) {
if(corner > 1.0f){
this.corner = 1.0f;
@@ -156,7 +156,7 @@ public abstract class RIButton extends UIShape {
}
dirty |= DIRTY_SHAPE;
}
-
+
public float getLabelZOffset() {
return labelZOffset;
}
@@ -178,7 +178,7 @@ public abstract class RIButton extends UIShape {
}
dirty |= DIRTY_SHAPE;
}
-
+
public float[] getButtonColor() {
return buttonColor;
}
@@ -193,21 +193,21 @@ public abstract class RIButton extends UIShape {
public float[] getLabelColor() {
return labelColor;
}
-
+
private UIRegion buttonRegion = null;
private UIRegion labelRegion = null;
private boolean toggle =false;
private boolean toggleable = false;
- public void render(GL2ES2 gl, RenderState rs, RegionRenderer renderer, int renderModes, int[/*1*/] texSize, boolean selection) {
+ public void render(GL2ES2 gl, RegionRenderer renderer, int renderModes, int[/*1*/] texSize, boolean selection) {
if(null == buttonRegion) {
buttonRegion = new UIRegion(this);
labelRegion = new UIRegion(getLabel());
- }
-
+ }
+
gl.glEnable(GL2ES2.GL_POLYGON_OFFSET_FILL);
gl.glPolygonOffset(0.0f, 1f);
-
+
float[] bColor = buttonColor;
if(isPressed() || toggle){
bColor = buttonSelectedColor;
@@ -215,9 +215,9 @@ public abstract class RIButton extends UIShape {
if(!selection){
renderer.setColorStatic(gl, bColor[0], bColor[1], bColor[2]);
}
- renderer.draw(gl, buttonRegion.getRegion(gl, rs, renderModes), texSize);
+ renderer.draw(gl, buttonRegion.getRegion(gl, renderer, renderModes), texSize);
gl.glDisable(GL2ES2.GL_POLYGON_OFFSET_FILL);
-
+
float[] lColor = labelColor;
if(isPressed() || toggle ){
lColor = labelSelectedColor;
@@ -225,7 +225,7 @@ public abstract class RIButton extends UIShape {
if(!selection){
renderer.setColorStatic(gl, lColor[0], lColor[1], lColor[2]);
}
- renderer.draw(gl, labelRegion.getRegion(gl, rs, renderModes), texSize);
+ renderer.draw(gl, labelRegion.getRegion(gl, renderer, renderModes), texSize);
}
public void setPressed(boolean b) {
super.setPressed(b);
@@ -233,21 +233,21 @@ public abstract class RIButton extends UIShape {
toggle = !toggle;
}
}
-
+
public void setLabelColor(float r, float g, float b) {
this.labelColor = new float[3];
this.labelColor[0] = r;
this.labelColor[1] = g;
this.labelColor[2] = b;
}
-
+
public void setButtonSelectedColor(float r, float g, float b){
this.buttonSelectedColor = new float[3];
this.buttonSelectedColor[0] = r;
this.buttonSelectedColor[1] = g;
this.buttonSelectedColor[2] = b;
}
-
+
public void setLabelSelectedColor(float r, float g, float b){
this.labelSelectedColor = new float[3];
this.labelSelectedColor[0] = r;
@@ -258,7 +258,7 @@ public abstract class RIButton extends UIShape {
public boolean isToggleable() {
return toggleable;
}
-
+
public void setToggleable(boolean toggleable) {
this.toggleable = toggleable;
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java
index 616dd9b98..7f0254ce6 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java
@@ -169,7 +169,7 @@ public class SceneUIController implements GLEventListener{
renderer.rotate(gl, rotation[1], 0, 1, 0);
renderer.rotate(gl, rotation[2], 0, 0, 1);
- shapes.get(index).render(gl, rs, renderer, renderModes, texSize, select);
+ shapes.get(index).render(gl, renderer, renderModes, texSize, select);
renderer.rotate(gl, -rotation[0], 1, 0, 0);
renderer.rotate(gl, -rotation[1], 0, 1, 0);
renderer.rotate(gl, -rotation[2], 0, 0, 1);
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java
index 0915ea523..bfb7d8487 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java
@@ -38,12 +38,12 @@ 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.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.opengl.test.junit.graph.demos.MSAATool;
import com.jogamp.opengl.test.junit.graph.demos.ui.opengl.UIRegion;
public class UIGLListener01 extends UIListenerBase01 {
-
+
public UIGLListener01 (RenderState rs, boolean debug, boolean trace) {
super(RegionRenderer.create(rs, 0), debug, trace);
setMatrix(-20, 00, 0f, -50);
@@ -56,7 +56,7 @@ public class UIGLListener01 extends UIListenerBase01 {
}
public void onRelease() {
}
-
+
};
button.setPosition(2,1,0);
/** Button defaults !
@@ -69,24 +69,24 @@ public class UIGLListener01 extends UIListenerBase01 {
} catch (IOException ex) {
System.err.println("Catched: "+ex.getMessage());
ex.printStackTrace();
- }
+ }
}
-
+
public void init(GLAutoDrawable drawable) {
super.init(drawable);
-
+
GL2ES2 gl = drawable.getGL().getGL2ES2();
gl.setSwapInterval(1);
gl.glEnable(GL2ES2.GL_DEPTH_TEST);
gl.glEnable(GL2ES2.GL_POLYGON_OFFSET_FILL);
-
+
MSAATool.dump(drawable);
}
UIRegion regionButton;
UIRegion regionLabel;
-
+
public void display(GLAutoDrawable drawable) {
GL2ES2 gl = drawable.getGL().getGL2ES2();
@@ -94,27 +94,26 @@ public class UIGLListener01 extends UIListenerBase01 {
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
final RegionRenderer regionRenderer = getRegionRenderer();
- final RenderState rs = regionRenderer.getRenderState();
-
+
regionRenderer.resetModelview(null);
-
+
regionRenderer.translate(null, getXTran(), getYTran(), getZoom());
regionRenderer.rotate(gl, getAngle(), 0, 1, 0);
-
+
final float[] bColor = button.getButtonColor();
- final float[] lColor = button.getLabelColor();
+ final float[] lColor = button.getLabelColor();
if(null == regionButton) {
regionButton = new UIRegion(button);
regionLabel = new UIRegion(button.getLabel());
- }
-
+ }
+
regionRenderer.setColorStatic(gl, bColor[0], bColor[1], bColor[2]);
regionRenderer.translate(gl, button.getPosition()[0], button.getPosition()[1], button.getPosition()[2]);
- regionRenderer.draw(gl, regionButton.getRegion(gl, rs, 0), null);
+ regionRenderer.draw(gl, regionButton.getRegion(gl, regionRenderer, 0), null);
regionRenderer.setColorStatic(gl, lColor[0], lColor[1], lColor[2]);
- regionRenderer.draw(gl, regionLabel.getRegion(gl, rs, 0), null);
- }
-
+ regionRenderer.draw(gl, regionLabel.getRegion(gl, regionRenderer, 0), null);
+ }
+
public void dispose(GLAutoDrawable drawable) {
GL2ES2 gl = drawable.getGL().getGL2ES2();
if(null != regionButton) {
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java
index 0577c5ff0..06a6f1e20 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java
@@ -33,7 +33,7 @@ import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.newt.event.KeyAdapter;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.WindowAdapter;
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java
index c38f8f75c..ff494a5ea 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java
@@ -31,7 +31,7 @@ import javax.media.opengl.GL2ES2;
import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.graph.curve.opengl.RegionRenderer;
-import com.jogamp.graph.curve.opengl.RenderState;
+import com.jogamp.graph.curve.opengl.Renderer;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.geom.Vertex.Factory;
import com.jogamp.opengl.math.geom.AABBox;
@@ -39,41 +39,41 @@ import com.jogamp.opengl.math.geom.AABBox;
public abstract class UIShape {
private final Factory<? extends Vertex> vertexFactory;
protected OutlineShape shape;
-
- protected static final int DIRTY_SHAPE = 1 << 0 ;
+
+ protected static final int DIRTY_SHAPE = 1 << 0 ;
protected int dirty = DIRTY_SHAPE;
-
+
private boolean down = false;
public UIShape(Factory<? extends Vertex> factory) {
this.vertexFactory = factory;
this.shape = new OutlineShape(factory);
}
-
+
public void clear() {
- clearImpl();
+ clearImpl(null, null);
shape.clear();
}
-
- public abstract void render(GL2ES2 gl, RenderState rs, RegionRenderer renderer, int renderModes, int[/*1*/] texSize, boolean selection);
-
+
+ public abstract void render(GL2ES2 gl, RegionRenderer renderer, int renderModes, int[/*1*/] texSize, boolean selection);
+
protected boolean positionDirty = false;
-
- private float[] position = new float[]{0,0,0};
- private float[] scale = new float[]{1.0f,1.0f,1.0f};
+
+ private final float[] position = new float[]{0,0,0};
+ private final float[] scale = new float[]{1.0f,1.0f,1.0f};
public void setScale(float x, float y, float z){
scale[0] = x;
scale[1] = y;
scale[2] = z;
}
-
+
public void setPosition(float x, float y, float z) {
this.position[0] = x;
this.position[1] = y;
this.position[2] = z;
positionDirty = true;
}
-
+
private void updatePosition () {
float minX = shape.getBounds().getLow()[0];
float minY = shape.getBounds().getLow()[1];
@@ -83,18 +83,18 @@ public abstract class UIShape {
setPosition(position[0] - minX, position[1] - minY, position[2] - minZ);
positionDirty = false;
}
-
- public float[] getScale() { return scale; }
+
+ public float[] getScale() { return scale; }
public float[] getPosition() { return position; }
-
- protected abstract void clearImpl();
-
- protected abstract void createShape();
-
+
+ protected abstract void clearImpl(GL2ES2 gl, Renderer renderer);
+
+ protected abstract void createShape(Renderer renderer);
+
public boolean updateShape() {
if( isShapeDirty() ) {
shape.clear();
- createShape();
+ createShape(null);
if(positionDirty){
updatePosition();
}
@@ -103,27 +103,27 @@ public abstract class UIShape {
}
return false;
}
-
- public final Vertex.Factory<? extends Vertex> getVertexFactory() { return vertexFactory; }
+
+ public final Vertex.Factory<? extends Vertex> getVertexFactory() { return vertexFactory; }
public AABBox getBounds() { return shape.getBounds(); }
-
- public OutlineShape getShape() {
- updateShape();
- return shape;
+
+ public OutlineShape getShape() {
+ updateShape();
+ return shape;
}
-
+
public boolean isShapeDirty() {
return 0 != ( dirty & DIRTY_SHAPE ) ;
- }
-
+ }
+
public void setPressed(boolean b) {
this.down = b;
}
-
+
public boolean isPressed() {
return this.down;
}
-
+
public abstract void onClick();
public abstract void onPressed();
public abstract void onRelease();
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UITextShape.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UITextShape.java
index ee79d9a0b..ce9073a30 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UITextShape.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UITextShape.java
@@ -27,11 +27,11 @@
*/
package com.jogamp.opengl.test.junit.graph.demos.ui;
-import jogamp.graph.curve.text.GlyphString;
+import com.jogamp.graph.curve.opengl.GLRegion;
/**
* Marker interface to mark a UIShape implementation for text usage
*/
public interface UITextShape {
- GlyphString getGlyphString();
+ GLRegion getRegion();
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/opengl/UIRegion.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/opengl/UIRegion.java
index 88271095c..01e1827ab 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/opengl/UIRegion.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/opengl/UIRegion.java
@@ -31,25 +31,26 @@ import javax.media.opengl.GL2ES2;
import com.jogamp.graph.curve.opengl.GLRegion;
import com.jogamp.graph.curve.opengl.RenderState;
+import com.jogamp.graph.curve.opengl.Renderer;
import com.jogamp.opengl.test.junit.graph.demos.ui.UIShape;
import com.jogamp.opengl.test.junit.graph.demos.ui.UITextShape;
public class UIRegion {
- protected static final int DIRTY_REGION = 1 << 0 ;
+ protected static final int DIRTY_REGION = 1 << 0 ;
protected int dirty = DIRTY_REGION;
-
- private UIShape uiShape;
+
+ private final UIShape uiShape;
private GLRegion region;
-
+
public UIRegion(UIShape uis) {
this.uiShape = uis;
}
-
- public boolean updateRegion(GL2ES2 gl, RenderState rs, int renderModes) {
+
+ public boolean updateRegion(GL2ES2 gl, Renderer renderer, int renderModes) {
if( uiShape.updateShape() || isRegionDirty() ) {
- destroy(gl, rs);
+ destroy(gl, renderer.getRenderState());
if(uiShape instanceof UITextShape) {
- region = ((UITextShape)uiShape).getGlyphString().createRegion(gl, renderModes);
+ region = ((UITextShape)uiShape).getRegion();
} else {
region = GLRegion.create(uiShape.getShape(), renderModes);
}
@@ -58,20 +59,20 @@ public class UIRegion {
}
return false;
}
-
- public GLRegion getRegion(GL2ES2 gl, RenderState rs, int renderModes) {
- updateRegion(gl, rs, renderModes);
- return region;
+
+ public GLRegion getRegion(GL2ES2 gl, Renderer renderer, int renderModes) {
+ updateRegion(gl, renderer, renderModes);
+ return region;
}
-
+
public boolean isRegionDirty() {
return 0 != ( dirty & DIRTY_REGION ) ;
}
-
+
public void destroy(GL2ES2 gl, RenderState rs) {
if(null != region) {
region.destroy(gl, rs);
region = null;
- }
+ }
}
}