Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (593)
Games in Android Showcase (168)
games submitted by our members
Games in WIP (646)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Shapes and Text3D  (Read 3090 times)
0 Members and 1 Guest are viewing this topic.
Offline Alistair_Dickie

Senior Newbie

Java games rock!

« Posted 2005-04-10 01:12:41 »

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 this

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 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:

Offline Alistair_Dickie

Senior Newbie

Java games rock!

« Reply #1 - Posted 2005-04-13 19:10:31 »

bump - any comments?
Offline William Denniss

JGO Coder

Projects: 2

Fire at will

« Reply #2 - Posted 2005-04-13 20:21:27 »

It looks really good although I'd like to see LWJGL support Smiley

I'm believe LWJGL does include support for GLU.

Nice one,


Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Ken Russell

JGO Coder

Java games rock!

« Reply #3 - Posted 2005-04-13 20:56:32 »

This looks really cool. Someone contacted me a while back about adding support for wglUseFontBitmaps and wglUseFontOutlines to JOGL but I suggested they look instead for a way to get Java2D font support instead. Your project looks like a general technique for the outline support part of that. Would you consider packaging this up in a utility class that could be placed in the JOGL utility package ( It would be great to have a Java2D Shape tesselator as well as something that conveniently made Java2D fonts available. Bitmap support would make it a grand slam.
Offline aNt

Senior Devvie


« Reply #4 - Posted 2005-04-14 06:53:45 »

Alistair: top work mate- looks real nice, i realy like this
a lot - and thanks for bring it to us all....
Offline Alistair_Dickie

Senior Newbie

Java games rock!

« Reply #5 - Posted 2005-04-15 10:48:49 »

Will: I am not sure about LWJGL. I had a quick look and it looked like the tess stuff was not fully done. I hope someone advises otherwise.

Ken: Yes we can put something like this into JOGL. I am a scenegraph person and know little about what to do with the verticies that I get back from the tess stuff to make them JOGL happy. If you look at my code I add them to a xith TriangleArray. I am sure that there is something that JOGL has that would be appropriate. In any case they should be cached somehow so you do not do the tess thing every frame. Something like my code will do a generalized Shape Tessalator (and its extrusion in one dimension  (I may add twists later)), and java.awt.Font text. What do you mean by bitmap support?

Offline Ken Russell

JGO Coder

Java games rock!

« Reply #6 - Posted 2005-04-15 14:55:48 »

Don't worry about the final representation of your vertices; we can play with this in the API. It looks like wglUseFontOutlines makes a display list per character in the font so maybe we can do something similar in the JOGL version of the API. Would you open an RFE using the JOGL Issue Tracker and attach a source code bundle? You'll need to request Observer status on the project to do this if you aren't one already. Thanks very much; this is great stuff.

(Edit) Regarding bitmaps: I was wondering if you had tried adding bitmap font support by rasterizing the font into a BufferedImage and then drawing the characters using textures.
Offline bohdan

Junior Devvie


« Reply #7 - Posted 2005-04-25 13:45:22 »

Like it! Good job! Thanks Smiley

But there is the problem.

Trying your "" with different text and it sometimes crashing:

Text = "f" - working fine
Text = "h" - working fine
Text = "hf" - working fine
Text = "fh" - ups... constantly crashing with error :  Error 100156 occured while tesselating a shape using the ShapeTriangulator

Strange... Any ideas? Smiley

Offline Alistair_Dickie

Senior Newbie

Java games rock!

« Reply #8 - Posted 2005-04-26 07:21:49 »

I was not handling when part of a shape3D intersected with another part. For the serif font fh actually overlaps at the top. So one segment was overlapping another. For the tesselation this means that one line segment crosses another. When this happens the gluTesselator stuff expects to be able to call combine(...) or combineData(...) I had not implemented either of these callbacks or set the gluTesselator to call them.

The fix is to change ShapeTriangulator in three spots. At around line 83 put in the following lines;

glu.gluTessCallback(tess, GLU.GLU_TESS_COMBINE_DATA, this);
    glu.gluTessCallback(tess, GLU.GLU_TESS_COMBINE, this);

Then alter the combine and combineData methods as follows:

public void combine(double[] coords, Object[] data, float[] weight, Object[] outData) {

     outData[0] = coords;
   * called by glu
   * @param coords
   * @param data
   * @param weight
   * @param outData
   * @param polygonData

  public void combineData(double[] coords, Object[] data, float[] weight, Object[] outData, Object polygonData) {
    outData[0] = coords;

Note that it is very important that outData[0] is set to something. It does not really matter what - it just has to be non null. It does not seem to be used in any meaningfull way.

This fix stops the program from crashing however the results are not perfect. I end up with a little hole where f and h intersect. After a bit of stuffing around I realised that I was not setting the winding rule of the gluTesselator to the same winding rule of the Shape. The following bit of code starting around line 86 does this.

int shapeWinding = iter.getWindingRule();
      case PathIterator.WIND_EVEN_ODD:
      case PathIterator.WIND_NON_ZERO:
        //just leave it set to whatever glu sets as default

I have updated the source file ( A screenshot of fh is shown below.

You may also note that I have added a Char3D and CachedText3D. These are designed to be used togheter to create a cache of Shape3D's for use in rapidly changing text. I intend to use this for a score counter.

I really should get this into CVS for xith3D. I seem to be able to check stuff out easy enough but can not seem to add. Can someone point me in the right direction?

Ken- For the moment I am not really sure where to start on the putting something together for jogl. The only direct jogl calls I have ever written are this gluTesselator stuff. I am happy for anyone to take this code and write a jogl specific implementation that has no reference to xith. I have done the bitmapped font but was never really happy with it. It is relatively easy to drawText on the graphics of a BufferedImage then use this as a texture for some quad.  



Offline Ken Russell

JGO Coder

Java games rock!

« Reply #9 - Posted 2005-04-27 15:57:09 »

Nice bug fix. Don't worry about adding the support to JOGL; if you have time to work on it, that would be great, but I've filed an RFE and attached your current source code to it so it can be taken care of later (without getting lost on these forums...)
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Riven (16 views)
2015-07-03 11:22:16

deepthought (43 views)
2015-06-30 15:39:44

deepthought (47 views)
2015-06-30 15:39:09

deepthought (57 views)
2015-06-30 15:36:52

Za\'Anzabar (27 views)
2015-06-29 05:44:54

TritonDreyja (43 views)
2015-06-24 17:10:40

CopyableCougar4 (42 views)
2015-06-23 00:34:45

BurntPizza (46 views)
2015-06-21 20:36:46

cookiecompiler (88 views)
2015-06-11 15:42:53

cookiecompiler (51 views)
2015-06-11 15:41:14
How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!