Newbie, trying to use Text


Managed to setup Eclipse and get it pointing to the CVS repository and can run the demo's etc. I even understand how to setup a SimpleGame environment and place 3d objects on it and have them animated. However, what I really want to do is something very basic in Java3d. I.E. I want to put a 3d text string on the screen and rotate it.

Can anyone confirm to me. From what I see, jME only supports bitmap fonts from a file currently? If so, are there any plans to enable True Type Fonts? I was planning to use jME for a frontend to some emulation stuff. I was going to use Java3d and literally ran into jME yesterday. I'm so impressed that I want to use this library instead. I want to understand the text processing first and add in the 3d graphics stuff later…

Thanks in advance… I've trawled as much as I can in a day… but I have to head home before the wife nags me to get home to wash the kid!!! I'm hoping someone may point me at a good example for the morning… Thanks in advance…



I was thinking about trying to do an implementation of TTF in jME directly a while back that would generate a Node with the text via a utility class and you could do something like: Utility.createTextNode(Font font, String text, float depth) and it would create the 2D text but add depth to it so it could be moved around in your 3D world.

In premise I wouldn't think this was too hard to do since Font already has:

GlyphVector createGlyphVector(FontRenderContext frc, String str);

I figured this could be used to translate to the 3D universe.  Is it a lot harder than I realize?



Thought I'd check my email as I've just got home. Thanks for your replies. I had seen the swing demo and was extremely impressed. However, I was only thinking that is ideal if you want a gui type interface. What I want to do is have a menu, ie:

Game 1

Game 2

Game 3

Game 4

The user scrolls through them etc, etc. So far, I know this can be done in Swing…

…However… What I want to do (is that the world on the stick sir?)… is to use the 3d world for drawing up the menu for instance. IE seperate each letter and have each of them transform from random vectors and moving to the final position in the menu. Or for flipping in from different angles, etc, etc. So having a font that can be scaled/transformed is a must.

Now I can see a bitmapped font can be used. However, aren't these going to look rather 2d? I.E. in Java3d (I know, its not a fair comparrison) I can select a True Type font and have it generated with Depth to create a 3d form.

Sorry, thoughts?


P.S. Thanks again, much appreciated… I'm off to get some shut eye. If you don't have time, don't worry… I'll play tomorrow! Looking forward to it…

It's 3D in the sense that you can rotate and scale it and such. However If you want to add "depth" to your text, you could follow darkfrog's idea… You'd need to implement drawing an AWT Shape as a 3D object (using it's PathIterator). That should be doable.

Perhaps another way could be using shaders on JMEDesktop or Text or otherwise generated texture(s).

I think darkfrogs idea to generate a bitmap font from a ttf font does not help if speedy wants to have something like this:

jME does not have that feature. Java3D can do that already?

But using AWT to extrude a ttf would surely be possible… make a 2D mesh from the path, copy, connect… but currently personally I’m satisfied with bitmap menus :slight_smile:

Yes, Irrisor… This is what I'm talking about. Here is a link to a tutorial regarding Java3d:

If goes on to discuss text/font extrusion. I have to confess I'm no expert in either Java3D, Fonts or jME. So I'm trying to make an initial judgement on whether jME is going to provide the functionality to create these menus. I love the 3d environment jME provides and as I say, I have a few objects created in a universe… I'm even willing to develop a text3d type solution if a good solution is stated (ie, I've got my ears open to darkfrog!).



P.S. I'd love to use jME to create a similar environment that 3dArcade frontend provides. However, I think although that frontend is fantastic, it is overly complex. I think jME and Java would provide the language to create a simple configuration file in XML etc, etc… Here's hoping!

What darkfrog suggested is getting the glyphs for drawing a String. He will then have to draw those glyphs himself into something which can be displayed in jME. (You can do that using the PathIterator of the Shape you can let AWT generate like I said).

Ofcourse, making that "3D" instead of "2D" is almost no extra effort.

Anyway, isn't Java3D partially under a BSD style license these days? If they already implement it this way porting it could be an option.


Looks like they use the method as thought up by darkfrog. You can browse the source (Text3D, Font3D):

However, j3d-core is NOT BSD style licensed. It's more in the "you should be happy we even let you look at this you inferior programmer" style. So I didn't look at it for too long. Also, it hurts my eyes the way J3D is implemented.

I don't know if I should take it as a compliment or as a dig that I was thinking of things the same way Java3D does. :-p

It's more in the "you should be happy we even let you look at this you inferior programmer" style.

You're one funny llama! :)

I have been thinking about implementing this idea as I'd like something similar (I don't really care about the depth, but I want TTF fonts) to this in Roll-A-Rama to display the name of each of the players above them without having to create a JMEDesktop for each player in the game.  It would also add some really cool effects to be able to show information like "Level 1" rotating around in 3D at the beginning of a level in a game.  I'm probably not going to get a chance to look into this before the end of this month, but I definitely need something like this before March so take heart sp33dy, we'll get you those features. :-p

BTW, I don't think a comparison between jME and Java3D is a fair one....Java3D sucks. :-p


Well you can paint something to BufferedImage, and put that in a texture. You don't need a complete JMEDesktop for showing some flat text in TTF.

It's true that doesn't give you depth yet. However, bumpmapping should give you a reasonable effect (see jmetest.renderer.state.TestFragmentProgramState)


OK, how do I convert the BufferedImage to the jme image format? I'm guessing this is what I need to do to populate a texture to then wrap over Quad (for simple test)…?



I think what llama proposes is using it as a texture to apply to a Quad or something?


Yep, I can understand what Llama is saying. Generate a bufferedImage with the text written to it (which I've got) and could display that easily in a Swing Window etc. However, I'm just figuring out the jME libraries. I see I need to convert the BufferedImage to a jME image and can't figure it out just yet. I see ByteBuffers are involved. Wondering whether there is a method that does this or if its a manual task…



P.S. If this works out, it'll be ideal for what I want (Except the 3d'ness of it, but hey… Its a great start)…

Ok, ignore me. Just found the HUD tutorials… That seems to have a piece about it… TA

Yes, which should be good enough for flat text on a highscore list right? Just to be sure: that still doesn't give you any depth!

The jME TextureManager accepts java.awt.Image for loading textures. eg:

Texture t1 = TextureManager.loadTexture(myimage,

You can also use ImageGraphics. if you have to update your texture continuously this would come in very handy :). Unfortunately there is no tutorial for it, but at least some JavaDoc in there…

Now there's a good plan :slight_smile:

Fantastic, ok, so the following is now working for me:

package ces;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;

import com.jme.image.Texture;
import com.jme.scene.shape.Quad;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;

public class FlatSide extends SimpleGame {

   public static void main(String[] args) {
      FlatSide app = new FlatSide();
   public void simpleInitGame() {
      Quad q = new Quad("Quad",3,3);
      BufferedImage buffer = new BufferedImage(100,100,true ? BufferedImage.TYPE_4BYTE_ABGR : BufferedImage.TYPE_3BYTE_BGR);
      Graphics g = buffer.createGraphics();
      g.drawString("Hello World",10,10);
      Image image = Toolkit.getDefaultToolkit().createImage(buffer.getSource());
      Texture t = TextureManager.loadTexture(image,Texture.MM_LINEAR,Texture.FM_LINEAR,true);

      TextureState ts = display.getRenderer().createTextureState();


Now I need to figure out how to draw these large first so scaling works nicely.. Thanks guys!! I guess I'm now going to use jME to start this frontend!!! Obviously, I've a long way to go and would like to figure out some more of the functionality.. but this is what I needed to be convinced...



hey wait a sec…what if you generated a bufferedimage and then were to use that to generate a terrain based on that as a heightmap?  I guess you can't make the non-text portion transparent can you?

It would give you TTF and depth but it would probably take up a lot more memory. :o



Yes, the non-text part can be turned into an alpha channel. There is also a way of clipping the image to the size required for the String (not coded yet). I plan to chunk individual characters up and have them flying all over the screen.

As for a terrain base, that makes sense in my head. However, I've no idea how to implement that or if it is costly in terms of processing or memory. I'd be very interested. I also wondered if its possible to layer several quads over each other to create the depth. IE use the same image but put it .000001 step below the last and say have 15 of them. This is how the 3d Text is created anyway.

For now this solution will do, but it certainly isn't ideal. The biggest problem with this is scalling. The closer you get, the more pixelated the image becomes. Which isn't very good. However, for my purposes, they'll zoom past this point very quickly and nestle at the correct size…



P.S. Sorry for hogging some people's time. I'm just interested and wanted to get moving as quickly as I could. I understand a lot of the theories, but none of the library!

Well, anything but actually generating a Spatial that correctly displays the text in 3D is really a hack at this point.  When I get around to this (probably next month) if nothing else has been done officially I'll write an implementation for this as I think it's definitely worth the time.