jME-TrueTypeFont Rendering Library

jME-TTF is a True Type Font(.ttf) rendering system for jMonkeyEngine3.1 and newer. With this library you can render UI text styles loaded directly from a true type font file at run-time. Characters from the ttf file are written to a dynamically sized texture atlas and then rendered on screen using a series of quads that display each character from the atlas. When requesting a text string to display jME-TTF looks through the string to see if any characters are missing from the atlas and if so adds them, expanding the size of the atlas texture as necessary.

In addition to that you can opt to render scaleable text styled from a true type font file in your 3D or 2D scenes. jME-TTF can triangulate a mesh from the glyph outline of each requested character, caching new glyph meshes, and apply a material that interpolates curved sections of the glyph’s contours using quadratic bezier formulas. The result is a text that can scale without pixelaltion and is fully compatible with modern GPU anti-aliasing methods.

jME-TTF provides a variety of conveniences such as getting the width of a line of text in pixels or world units, the line height, visual heights, scaling and kerning, you can even get a texture displaying blurred text. Formatting options such as vertical/horizontal alignment and text wrapping are also available. The zip file download contains the jME-TTF.jar library, javadoc and source code. jME-TTF depends upon Google’s Sfntly librari which is included in the download.

Fonts are easy enough to load:

assetManager.registerLoader(TrueTypeLoader.class, "ttf");

TrueTypeKeyMesh ttk = new TrueTypeKeyMesh("Interface/Fonts/myTypeface.ttf",
    Style.Plain, 16);
TrueTypeFont ttf = (TrueTypeMesh)assetManager.loadAsset(ttk);

TrueTypeContainer ttc = ttf.getFormattedText(new StringContainer(ttf, "Hello\nWorld"), 0, ColorRGBA.Blue);
rootNode.attachChild(ttc);

jME-TTF is licensed under the Free Public License 1.0.0 while the jmescher triangulation included in the library is licensed under New BSD. Sfntly is licensed under Apache 2.0.

Anyway you can download the library and view information on how to use it on my website here: 1337 Gallery - jME-TTF

38 Likes

By the by, I forgot to mention that the mesh triangulator doesn’t seem to like small distances so some glyphs with thin lines don’t triangulate well at smaller point sizes. In that case just try a larger point size and scale it back down.

5 Likes

What’s your license? For your part of the software?

Maybe I can find a replacement for the delauny triangulator, that’s why I’m asking. Because only then this would be of real interest for me since I plan to go commercial soon.

1 Like

Far as I’m concerned you can use my code for commercial purposes. Does jDelaunay’s GPLv3 prevent commercial uses or something?

Yes (some hardcore GPL fans may say “no”, but effectively GPL forces me to publish my whole code under the same license). Does also apply to everone using this software in its current state. That’s why the jME license is so great (to me) because it’s really free. LGPL is okay for me too since I can live with LGPL limitations, but not with GPL limitations.

1 Like

That’s pretty shitty. Tell ya what, if you don’t need the scaleable text stuff, just UI text, I’ll post a library with just the dynamic texture atlas bitmap font stuff because that doesn’t need jDelaunay or JTS.

1 Like

Oh, don’t feel forced to do that. I mean, every bit of such code published here is fine for people having similar intentions like me, but don’t think that I think that you should do it. :chimpanzee_closedlaugh:

When my “little” game (23k loc and counting) is done, I have more time for font-stuff. In the meantime it was sleeping peacefully and is waiting to be reactivated - but it may take some weeks until I’m back on that font project…

Btw, it would be cool, to make something like that with your text too: Labeling a geometry - #5 by Ogli

I don’t feel forced at all. All it would take is to copy portions of it over to a new project leaving out the mesh glyph stuff then building and uploading it, wouldn’t need to make any actual changes to the code.

Okay if you head back to the link in my original post you will see the new jME-TrueTypeFontLite package is now available. This packages strips jME-TrueTypeFont of the ability to create scaleable mesh texts, but retains the ability to create UI texts. This removes the jDelaunay and JTS Topology Suite dependencies.

I went ahead and took this opportunity to add an additional feature to both jME-TrueTypeFont and jME-TrueTypeFontLite. You can now draw an outline around your UI texts. Just specify an outline size, in pixels, in the TrueTypeKey constructor:

TrueTypeKey ttk = new TrueTypeKey("Interface/Fonts/myTypeface.ttf", 
    java.awt.Font.PLAIN, 48, 2);

TrueTypeFont ttf = (TrueTypeFont)assetManager.loadAsset(ttk);

The last value in the constructor is the thickness of the outline. Once you have an outline:

Geometry geom = ttf.getBitmapGeom("Hello World", new ColorRGBA(1, 1, 1, 0.5f), ColorRGBA.Blue);

int x = (settings.getWidth() / 2) - (ttf.getLineWidth("Hello World") / 2);
int y = (settings.getHeight() / 2) - (ttf.getVisualLineHeight("Hello World") / 2);

geom.setLocalTranslation(x, y, 0);

guiNode.attachChild(geom);

The first ColorRGBA in getBitmapGeom is the color of the text, the second is the color of the outline.

The above is a 48pt font scaled to 38pt using the TrueTypeFont.setScale(float scale) method.

4 Likes

Maybee this one could help?

It is under a apache license.

2 Likes

Good lookin out friend. However; it needs to be a constrained Delaunay triangulation. We need to be able to preserve the contours of the glyph. A constrained Delaunay triangulation allows a number of predefined edges to be preserved.

A normal Delaunay triangulation just takes in a set of points and creates triangles, favoring larger angles. Those triangles generally don’t keep the edges where they need to be, I tried one early on :slight_smile:

Interesting factoid I learned while working on jME-TrueTypeFont. Boris Delaunay, or Delone, was actually a student of Georgy Voronoi, or Voronoy. The same of what us graphics guys probably know of as the Voronoi Diagram. When you connect the mid-points of each triangle’s circum-circle in a Delaunay Triangulation you get a Voronoi Diagram :slight_smile:

2 Likes

So, the light version doesnt depend on GPLv3 neither LGPL libs, that will be very useful thx!

But, I downloaded it and it has no license at all (or I couldnt find it?).

I wonder if it could be released under some license compatible with JME’s one like BSD 3 clause or Apache 2.0 like is google’s guava?

Look in the source code:
/*

  • Feel free to use, modify, and/or distribute this source code for personal,
  • educational, commercial or any other reason you may conceive with or without
  • credit. There are absolutely no restrictions on the use, modification or
  • distribution of this code.
    */
1 Like

cool thx! So, it basically seems as permissive as a BSD 3 clause. Those huge licenses are so complicated to read… I released my CommandsConsoleGUI under BSD 3 clause because it is very short, goes straight to the point and also protects me :). Your lib will be a great addon to it! thx again!

Seems to be more like CC0. :chimpanzee_smile:

1 Like

Or the WTFPL

4 Likes

LOL - that license name… :chimpanzee_closedlaugh:

Humans often make mistakes and I am but only human. Therefore I leave up to you the choice to do as you please with what I produce. What you choose to do with it may be right or wrong and I do not claim to know what is right and what is wrong therefore it would be unfair of me to impose my likely flawed point of view upon you.

That in and of itself may be the wrong thing to do, but at least I am not imposing that choice upon you for you are welcome to release what I produce under your own license if you so choose.

The statement above my code is meant to convey that what I produce could be treated by you as if it were a random stick found in the woods. It belongs to no one and you found it so you could do with it literally anything that is physically possible.

3 Likes

just past that at the top of your code, its now under TL or Tryder Licence =)

1 Like

I’d call it “The stick in the wood” license… TSITW License.

1 Like