0
\$\begingroup\$

I'm using libGDX for my android game in which I'm trying to use bitmap fonts. I have created .fnt and .png bitmap files using Bitmap font generator of angel code.Both .fnt and .png have been placed under same folder /asset/data in my project.

Now when I try to run my project I get exception errors. Here is my sample code -

FileHandle handle = Gdx.files.internal("data/calib.fnt");
FileHandle handle2 = Gdx.files.internal("calib_0.png");
font = new BitmapFont(handle,handle2,true);
font.draw(batchmaker, "abcdef", x,y);

The error on console looks like this (showing only relevant lines):

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Error loading font file: data/calib.fnt . . . at com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.(BitmapFont.java:809) Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Invalid font file: data/calib.fnt

I do not believe this error has something to do with issue with paths, because it gives me different errors when I play around by changing the paths.

I have been trying to fix this since almost last 2 days but couldn't come up with a solution. Can someone please let me know what could be the problem or am I missing something?

Edit: Or could there be some checks in which the parameters of calib.fnt is not passing (due to upper/lower case name mismatch with libGDX lib files) ? Please help!

\$\endgroup\$
1
  • \$\begingroup\$ Check png file containing folder. Try it to put in same folder in which your fnt file is \$\endgroup\$
    – MGDroid
    Mar 31, 2014 at 6:23

3 Answers 3

0
\$\begingroup\$

I will show you all the procedure of implementing BitmapFonts in LibGdx :

  1. Download Hiero : https://code.google.com/p/libgdx/downloads/detail?name=hiero.jar&can=2&q=

  2. Open it and generate your font (create .fnt and .png files)

  3. In LibGdx :

    BitmapFont font;
    
    font = new BitmapFont(Gdx.files.internal("fonts/font.fnt"), Gdx.files.internal("fonts/font.png"), false); 
    
    font.draw(spriteBatch, str, fX, fY);
    
\$\endgroup\$
0
\$\begingroup\$

You should either not pass the .png file at all in your BitmapFont constructor (since the glyph images for your font are loaded from the font .png provided along with the .fnt file anyway, if you don't indicate some other texture region), or at least indicate the same path in the FileHandle initializing row as in the one for the .fnt file. You said they are both in the same location, so make it to be the same in your code as well (one is "data/calib.fnt" and the other one is "calib_0.png").

\$\endgroup\$
0
\$\begingroup\$

The issue was with the bitMap font generator tool I was using. It was BitMap Font generator from angel code. Now I switched to hiero and it works magically.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .