Changing font of Text

Hi all…its me again :frowning:



I am trying to change the font of a com.jme.scene.Text object. But am failing to see how that is possible…do i have to set some sort of blend state?



Can you guide me towards which is the best method or even Object to use (so possibly com.jme.scene.Text is a poor choice)…



I am trying to display some 2D text on the screen and am already using the ORTHO mode for it. It displays properly just wanna change how it looks…



Thank you very much

Mo

You should have a look at the angelfont. Actually I'm not so sure about what fonts you can use there and where to get them from. I only used the standard one. Have a look here (or better in your own svn):



http://jmonkeyengine.googlecode.com/svn/trunk/src/jmetest/text/TestBitmapFont.java

Anglefont is quite new and was not included to jme2.0

Actually it should be part of jme2.0.1 (…I downloaded jme2.0.1-stable and

of course it is included. )



All the libs are in jme2.0.1_stable/lib



I just can give you the advice to use jme2 through svn as it is under heavy development

and every day there are changes…


Hey guys…

Erm im kinda encountering some problems here. Netbeans reports that the com.jmex.anglefonts.* does not exist in the library (im using jME2.0).



I've added the the jme2.0.jar as a library to Netbeans globally. Everything else works just fine. Any ideas what I should be doing?



Also, jme2.1 does not seem to come with one global jme2.1.jar file, so how can I a proper jar library to my project so that my applications jar would be executable…?



Once I sort out this problem, I'll sort out the text problem.



Thank you

ttrocha said:

Actually I'm not so sure about what fonts you can use there and where to get them from. I only used the standard one. Have a look here (or better in your own svn):


You can create a BitmapFont from ANY font on your system and with ANY characters ( even korean, chinese, ciryllic, ...) using the AngelCode Font Generator http://www.angelcode.com/products/bmfont/

hey all, thanks for the replies…



I have looked into Text, Text2D (and Font2D), AND Text3D (and Font3D)…



Here is the trouble:



Text: You can't change any of the formatting…as someone said on the forum, it is more likely used for debugging…



Text2D (and Font2D): If I DONT use the default font provided by the Font2D class, I get a white rectangle, where the text should really be. In Text, the text was white and the background was transparent.



Text3D (and Font3D): I'm not really bothered with the face of the font, but rather the size. Seems like the size always stays the same, even though I try and change both Font3D and Text3D 's sizes. I also update the renderState and ModelBound…



When I call setSize() to change the font-size (or from the constructor) all it happens is that the Letter-Spacing changes accordingly… which is kinda pointless for me…



On top of all of this, I get the following error:


Sep 16, 2009 11:00:55 AM com.jmex.font3d.math.Triangulator$1SweepLineStatus getLeftOf
WARNING: We could find no left of {(real  )5(0.184375,0.765625)->4:(0.31875,0.578125),Helper:null,angle:-0.94897205}: 0.184375
Sep 16, 2009 11:00:55 AM com.jmex.font3d.Font3D <init>
WARNING: Error in char: (41:)), the following is most likely due to glyphs constructed from other glyphs.... that does not work.
java.util.NoSuchElementException
        at java.util.TreeMap.key(TreeMap.java:1206)
        at java.util.TreeMap$NavigableSubMap.lastKey(TreeMap.java:1435)
        at java.util.TreeSet.last(TreeSet.java:384)
        at com.jmex.font3d.math.Triangulator$1SweepLineStatus.getLeftOf(Triangulator.java:164)
        at com.jmex.font3d.math.Triangulator.generateMonotonePolygons(Triangulator.java:223)
        at com.jmex.font3d.math.Triangulator.triangulate(Triangulator.java:88)
        at com.jmex.font3d.Glyph3D.triangulate(Glyph3D.java:143)
        at com.jmex.font3d.Font3D.<init>(Font3D.java:160)
        at View.Renderer.HUD.<init>(HUD.java:34)
        at View.Renderer.Renderer.init(Renderer.java:48)
        at Controller.Game.initGame(Game.java:81)
        at com.jme.app.BaseGame.start(BaseGame.java:74)
        at Controller.Main.main(Main.java:14)


--
It really is bugging me! Please help. Also there is no point of me changing the face of the font when I can't change the size of the font.
--

If you want to have a look at the preview, here is an screenshot:
http://www.mofirouz.com - first post, scroll down should be there
mofirouz said:

I have looked into Text, Text2D (and Font2D), AND Text3D (and Font3D)...


Have you checked out BitmapFont too?

…so real cool you tested the BitmapFont we both talked about…

Hey…



I did use BitMap for Text2D…which is why I got the white rectangle…



I'm gonna try and figure out the BitMapText and BitMapFont, lets see whether that would be any miracle!



Will let you know…



Thanks

Hey thanks for the heads up!



I managed to integrate everything in, and compile everything properly. Now back to the main problem (LOL) :



BitmapFont fnt = BitmapFontLoader.loadDefaultFont();
BitmapText txt_gs_1 = new BitmapText(fnt, false);
txt_gs_1.setSize(32);
txt_gs_1.update();
txt_gs_1.setText(msg);
txt_gs_1.updateWorldBound();
txt_gs_1.update();
hudNode.attachChild(txt_gs_1);

hudNode.updateRenderState();
rootNode.updateRenderState();



Here is the problem: NOTHING SHOWS UP! In the previous tries (with T1/2/3D), the text used to show up on the left-bottom corner of the screen. In this case nothing shows up!

Any idea?

Regards Mo

Did you try the Test? And where is the difference between the test and your code?

No I didnt compile the code and run it, but I did copy and paste the code (ofc change variable names etc etc).



There is absolutely no difference between my one and the test. I literally copied the code and pasted into my project.



Right now I am using JME2.0.1 and its compiling just fine.



Also, having a look at the log, it says that BitmapFont was attached to node "hud" (my node's name). However i clearly did,



        BitmapFont fnt = BitmapFontLoader.loadDefaultFont();
        BitmapText txt_gs_1 = new BitmapText(fnt, false);
        txt_gs_1.setSize(32);
        txt_gs_1.update();
        txt_gs_1.setBox(new Rectangle(10, -10, display.getWidth() - 20,
                                display.getHeight() - 20));

        txt_gs_1.setText("Helooooo1");
        txt_gs_1.setDefaultColor(ColorRGBA.green.clone());
        txt_gs_1.updateWorldBound();
        txt_gs_1.update();

        hudNode.attachChild(txt_gs_1);

        hudNode.updateRenderState();
        rootNode.updateRenderState();



To me, it looks exactly like the test code. Please help, otherwise i have to figure out some bizarre way of adding some ugly thing to the application.

Thank you

Well,…don't think that this is the right going on. In jme_stable you have also the jme_test-folder.

There is in jmetest.text the TestBitmapFont-Class. Try this first…and first try to modify the test so

it fits to your requirements. And then try to port it to your code.



Just using some code somehow let's too much room for errors. So if you want us to help you ensure that.

your text is below the visible area, try a:

         txt_gs_1.setBox(new Rectangle(10, 50, display.getWidth() - 20,
                                display.getHeight() - 20));



;)

hey thank you thank you thank you…



to both you and ttrocha, for bearing with me…



thank you :slight_smile:

guys, sorry, seems like i need to spoon feed,



erm, need to add transparency to the BitmapText…



I have added:


        BlendState bs = display.getRenderer().createBlendState();
        bs.setBlendEnabled(true);
        bs.setSourceFunctionAlpha(BlendState.SourceFunction.SourceAlpha);
        bs.setDestinationFunctionAlpha(BlendState.DestinationFunction.OneMinusConstantAlpha);
        bs.setBlendEquation(BlendState.BlendEquation.Subtract);
        bs.setTestEnabled(false);
        bs.setEnabled(true);

// this is after i have added text, and setLocalTranslation() ....

        txt_gs_1.setRenderState(bs);
        txt_gs_1.updateModelBound();
        txt_gs_1.updateRenderState();



yet i fail to get rid of the black corners of each character....

please advise.

Thank you

you BlendState is incorrect, the standard blendstate should work just fine:



        BlendState bs = display.getRenderer().createBlendState();
        bs.setBlendEnabled(true);
        bs.setTestEnabled(false);
        bs.setEnabled(true);