I thought it was going to be pretty easy to write some code to create extruded shapes (of which text is a subset). I was wrong.
The main problem was to take a java.awt.Shape and make triangles of it. Triangulation is not easy. Java3D uses some very complex code to make Text. After almost a week of stuffing around, toying with my own triangulation code, and generally going mad, I found thishttp://www.geocities.com/foetsch/extrude/extrude.htm
It was pretty much exactly what I was after. Someone has been nice enough to include a glu port in jogl so from there on it only took a day or so.
You can now do three things pretty easily.
- Create a TriangleArray from a java.awt.shape object for both an extruded and flat version.
- Make a Text2D shape that is flat text from java.awt.font
- Make a Text3D shape that is extruded text.
It is not super fast and I would not suggest creating these objects on the fly whilst rendering.
The simple version of what I do to render text from a java.awt.Font is to get the Glyphs from the font (they are Shape objects), get a PathIterator from the Shape, pass the path to glu and get triangles back then create a TriangleArray for the front back and sides.
Because I use glu from JOGL this will not currently work with LWJGL. I am not sure if there is a glu port in LWJGL. If so it should be pretty easy for someone to copy what I have done.
You can get my source at http://alistairdickie.com/shapegeom_src.zip
. It is even commented and has an example! I have it in a package org.xith3d.shapegeom. At some stage it could be incorporated however I want a little feedback first. Run the test to have a play org.xith3d.shapegeom.Text3DTest
A few screenshots: