Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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 2750 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
http://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:


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,

Will.

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 (net.java.games.jogl.util)? 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 Member




AFK


« 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 Member




Java-positive...


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

Like it! Good job! Thanks Smiley

But there is the problem.

Trying your "Text3DTest.java" 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

Sincerely,
Bohdan.
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;

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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
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.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
int shapeWinding = iter.getWindingRule();
    switch(shapeWinding){
      case PathIterator.WIND_EVEN_ODD:
        glu.gluTessProperty(tess,GLU.GLU_TESS_WINDING_RULE,GLU.GLU_TESS_WINDING_ODD);
        break;
      case PathIterator.WIND_NON_ZERO:
        glu.gluTessProperty(tess,GLU.GLU_TESS_WINDING_RULE,GLU.GLU_TESS_WINDING_NONZERO);
        break;
      default:
        //just leave it set to whatever glu sets as default
       break;
    }


I have updated the source file (http://alistairdickie.com/shapegeom_src.zip). 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.  

Regards,

Alistair

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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (35 views)
2014-09-24 16:13:29

Pippogeek (28 views)
2014-09-24 16:12:22

Pippogeek (17 views)
2014-09-24 16:12:06

Grunnt (40 views)
2014-09-23 14:38:19

radar3301 (23 views)
2014-09-21 23:33:17

BurntPizza (58 views)
2014-09-21 02:42:18

BurntPizza (29 views)
2014-09-21 01:30:30

moogie (34 views)
2014-09-21 00:26:15

UprightPath (47 views)
2014-09-20 20:14:06

BurntPizza (51 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!