Skip to content

Commit a622fdd

Browse files
authored
Export Default.fnt and Console.fnt as j3o with embedded image data
The fonts Default.fnt and Console.fnt reference PNG textures (Default.png, Console.png) which require StbImageLoader from jme3-plugins to load. jme3-android and jme3-ios include General.cfg (which registers StbImageLoader) but only depend on jme3-core, not jme3-plugins, causing failures when the engine tries to display the default stats/UI. Fix: export both fonts as .j3o binary files with the texture image data embedded directly (no asset key, so no PNG loader needed at runtime). Update all jme3-core load sites to use the .j3o variants. Add DefaultFontJ3oTest to verify Default.j3o loads without a PNG loader.
1 parent ac91c6a commit a622fdd

8 files changed

Lines changed: 51 additions & 6 deletions

File tree

jme3-core/src/main/java/com/jme3/app/DetailedProfilerState.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ protected void initialize(Application app) {
108108

109109
ui.attachChild(darkenStats);
110110
ui.setLocalTranslation(app.getCamera().getWidth() - PANEL_WIDTH, app.getCamera().getHeight(), 0);
111-
font = app.getAssetManager().loadFont("Interface/Fonts/Console.fnt");
112-
bigFont = app.getAssetManager().loadFont("Interface/Fonts/Default.fnt");
111+
font = app.getAssetManager().loadFont("Interface/Fonts/Console.j3o");
112+
bigFont = app.getAssetManager().loadFont("Interface/Fonts/Default.j3o");
113113
prof.setRenderer(app.getRenderer());
114114
rootLine = new StatLineView("Frame");
115115
rootLine.attachTo(ui);

jme3-core/src/main/java/com/jme3/app/SimpleApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public void setShowSettings(boolean showSettings) {
248248
* @return the loaded BitmapFont
249249
*/
250250
protected BitmapFont loadGuiFont() {
251-
return assetManager.loadFont("Interface/Fonts/Default.fnt");
251+
return assetManager.loadFont("Interface/Fonts/Default.j3o");
252252
}
253253

254254
@Override

jme3-core/src/main/java/com/jme3/app/StatsAppState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public void initialize(AppStateManager stateManager, Application app) {
155155
}
156156

157157
if (guiFont == null) {
158-
guiFont = app.getAssetManager().loadFont("Interface/Fonts/Default.fnt");
158+
guiFont = app.getAssetManager().loadFont("Interface/Fonts/Default.j3o");
159159
}
160160

161161
loadFpsText();

jme3-core/src/main/java/com/jme3/app/StatsView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public StatsView(String name, AssetManager manager, Statistics stats) {
8282
statLabels = statistics.getLabels();
8383
statData = new int[statLabels.length];
8484

85-
BitmapFont font = manager.loadFont("Interface/Fonts/Console.fnt");
85+
BitmapFont font = manager.loadFont("Interface/Fonts/Console.j3o");
8686
statText = new BitmapText(font);
8787
statText.setLocalTranslation(0, statText.getLineHeight() * statLabels.length, 0);
8888
attachChild(statText);

jme3-core/src/main/java/com/jme3/input/virtual/VirtualJoystickTheme.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
*/
4646
public class VirtualJoystickTheme implements Savable {
4747

48-
private static final String DEFAULT_FONT = "Interface/Fonts/Default.fnt";
48+
private static final String DEFAULT_FONT = "Interface/Fonts/Default.j3o";
4949

5050
public enum TextureKey {
5151
BUTTON,
261 KB
Binary file not shown.
266 KB
Binary file not shown.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.jme3.asset;
2+
3+
import com.jme3.asset.plugins.ClasspathLocator;
4+
import com.jme3.export.binary.BinaryLoader;
5+
import com.jme3.font.BitmapFont;
6+
import com.jme3.font.plugins.BitmapFontLoader;
7+
import com.jme3.material.plugins.J3MLoader;
8+
import com.jme3.shader.plugins.GLSLLoader;
9+
import com.jme3.texture.plugins.DDSLoader;
10+
import com.jme3.texture.plugins.PFMLoader;
11+
import org.junit.jupiter.api.Test;
12+
13+
import static org.junit.jupiter.api.Assertions.assertNotNull;
14+
15+
/**
16+
* Verifies that Default.j3o (with embedded image data) can be loaded using only
17+
* the loaders available in jme3-core, without depending on the PNG loader from
18+
* jme3-plugins. This is needed for Android/iOS which don't depend on jme3-plugins.
19+
*/
20+
public class DefaultFontJ3oTest {
21+
22+
@Test
23+
public void testDefaultFontJ3oLoadsWithoutPngLoader() {
24+
// Create an AssetManager with only jme3-core loaders (no PNG loader)
25+
DesktopAssetManager assetManager = new DesktopAssetManager(false);
26+
assetManager.registerLocator("/", ClasspathLocator.class);
27+
28+
// Register only the loaders available in jme3-core (matching General.cfg, minus StbImageLoader/WebpImageLoader)
29+
assetManager.registerLoader(BitmapFontLoader.class, "fnt");
30+
assetManager.registerLoader(J3MLoader.class, "j3m", "j3md");
31+
assetManager.registerLoader(DDSLoader.class, "dds");
32+
assetManager.registerLoader(PFMLoader.class, "pfm");
33+
assetManager.registerLoader(BinaryLoader.class, "j3o", "j3f");
34+
assetManager.registerLoader(GLSLLoader.class, "vert", "frag", "geom", "tsctrl", "tseval", "glsl", "glsllib", "comp");
35+
36+
// This should succeed: Default.j3o has embedded image data (no PNG loader needed)
37+
BitmapFont font = assetManager.loadFont("Interface/Fonts/Default.j3o");
38+
assertNotNull(font, "Default.j3o should load without a PNG loader");
39+
assertNotNull(font.getPage(0), "Default.j3o should have at least one material page");
40+
assertNotNull(font.getPage(0).getTextureParam("ColorMap"),
41+
"Default.j3o material page should have a ColorMap texture");
42+
assertNotNull(font.getPage(0).getTextureParam("ColorMap").getTextureValue().getImage(),
43+
"Default.j3o texture should have embedded image data (no key needed)");
44+
}
45+
}

0 commit comments

Comments
 (0)