[Solved] Crash when trying to load TGA font via assetmanager.loadFont

Hey folks,

I’ve been hacking on my UI and trying to get something to display with a custom font, but I’ve run into a bit of a problem. Here’s the code:

    AssetManager am = sapp.getAssetManager();
    defaultUIFont = am.loadFont("Textures/ui/Liberation-Serif_0.tga");

Here, AssetManager seems to call out to com.jme3.textures.plugins.TGALoader to do the job - all well and good. However, when trying to run this, I get the following error:

java.lang.IllegalArgumentException: Texture assets must be loaded using a TextureKey
	at com.jme3.texture.plugins.TGALoader.load(TGALoader.java:77)
	at com.jme3.asset.DesktopAssetManager.loadLocatedAsset(DesktopAssetManager.java:272)
	at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:388)
	at com.jme3.asset.DesktopAssetManager.loadFont(DesktopAssetManager.java:434)
	at com.mygame.gui.FieldMenuController.initialize(FieldMenuController.java:123)
    ...

I can’t replace my path with a TextureKey for the same path, because LoadFont doesn’t accept one. I searched for this on the forum and came up empty, but other people seem to have been using tga fonts fine, so I must be doing something wrong - I just can’t figure out what. I also can’t find a converter for .tga to .fnt, which you’d think would be fairly simple but is, somehow, not. The javadoc for TGALoader isn’t very helpful, containing only the boilerplate descriptions that come with any resource loader interface implementation. If anyone can provide insight, I’d appreciate it.

TGA is propably fine as the font face / image. But the loadFont() must be used to load the bitmap font specification. Not the image. It wouldn’t know what to do with a image file. The bitmap font specification file references the actual font image files, which I’m sure can be TGAs.

This is what I’m referring to with bitmap font specification:
https://www.angelcode.com/products/bmfont/doc/file_format.html

1 Like

I straight up missed the .fnt file dropping in the same folder as the .tga file, whoops. Yeah, I’m good now.

2 Likes