The GLText class can (hopefully) do this by using bezier-curves.
It's basically using AWTGLCanvas or any other component where we could get a Font :
- Code: Select all
final Font font = gld.getFont();
final GlyphVector gv = gld.getFont().createGlyphVector(new FontRenderContext(font.getTransform(), true, false), text);
Then comes the tricky bezier computation that will be stored in a GL list using a Shape PathIterator :
- Code: Select all
GLList gllist = new GLGlyph(glyphChar, font.getSize()) {
@Override
public Runnable getList() {
return new Runnable() {
public void run() {
Shape glyph = gv.getGlyphOutline(indexChar, -(float) glyphBounds.getX(), -(float) glyphBounds.getY());
PathIterator pi = glyph.getPathIterator(null);
Point2D.Float current = new Point2D.Float();
while (!pi.isDone()) {
float[] coords = new float[6];
int path = pi.currentSegment(coords);
switch (path) {
case PathIterator.SEG_MOVETO:
/*System.err.println("PaIt begin move"); */
GL11.glBegin(GL11.GL_LINE_LOOP);
GL11.glVertex2f(coords[0], coords[1]);
current.x = coords[0];
current.y = coords[1];
break;
case PathIterator.SEG_CLOSE:
/*System.err.println("PaIt close");*/
GL11.glEnd();
break;
case PathIterator.SEG_LINETO:
/*System.err.println("PaIt line");*/
GL11.glVertex2f(coords[0], coords[1]);
current.x = coords[0];
current.y = coords[1];
break;
case PathIterator.SEG_CUBICTO:
/*System.err.println("PaIt cubic");*/
for (Point2D.Float p : _computeBezierCurve(new Point2D.Float[]{current, new Point2D.Float(coords[0], coords[1]), new Point.Float(coords[2], coords[3]), new Point.Float(coords[4], coords[5])}, font.getSize())) {
GL11.glVertex2f(p.x, p.y);
}
current.x = coords[4];
current.y = coords[5];
break;
case PathIterator.SEG_QUADTO:
/*System.err.println("PaIt quad");*/
for (Point2D.Float p : _computeBezierCurve(new Point2D.Float[]{current, new Point2D.Float(coords[0], coords[1]), new Point.Float(coords[2], coords[3])}, font.getSize())) {
GL11.glVertex2f(p.x, p.y);
}
current.x = coords[2];
current.y = coords[3];
break;
default:
break;
}
pi.next();
}
}
};
}
};
This way seems faster on rendering and is totally dependent of the current Font used when the method is invoked. That's if Font.size changes, then the renderer will increase the size too; as well as the Font.name changes then everything appear in the new font character (that case hasn't been tested yet).
THE ORIGINAL POST IS AT LWJGL with a source file sample : http://lwjgl.org/forum/index.php/topic,3028.0.html
