I would like to have Angelfont's BitmapText used as a floating text inside a 3D-scene. Tried doing that inside the big scene and using also BillboardNode, but could get text to render. After that I made a test that replaced the BitmapTexts with a quads everything seemed to work as expected.
Tried to search, but could not find anything related to this. So now I'm posting the question here. JME codebase has some example code, but it's only for the 2D case.
I modified the JME example code to work in 3d, but it doesn't seem to work. What I'm doing wrong here? Should the BitmapText even work in 3D?
Change the value of "caseNumber" to see the working cases.
import java.util.concurrent.Callable;
import com.jme.bounding.BoundingBox;
import com.jme.input.MouseInput;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.Spatial.CullHint;
import com.jme.scene.shape.Quad;
import com.jme.system.DisplaySystem;
import com.jme.util.GameTaskQueueManager;
import com.jmex.angelfont.BitmapFont;
import com.jmex.angelfont.BitmapFontLoader;
import com.jmex.angelfont.BitmapText;
import com.jmex.angelfont.Rectangle;
import com.jmex.game.StandardGame;
import com.jmex.game.state.DebugGameState;
import com.jmex.game.state.GameStateManager;
public class TestFont {
public static void main(String[] args) throws Exception {
final StandardGame game = new StandardGame("Test BitmapFont & BitmapText");
game.start();
final String txtB = "This extension provides a mechanismn to specify vertex attrib and "
+ "element array locations using GPU addresses.";
GameTaskQueueManager.getManager().update(new Callable<Void>() {
public Void call() throws Exception {
MouseInput.get().setCursorVisible(true);
DisplaySystem.getDisplaySystem().getRenderer().setBackgroundColor(ColorRGBA.gray.clone());
final DebugGameState debug = new DebugGameState();
GameStateManager.getInstance().attachChild(debug);
debug.setActive(true);
// Create the text node
BitmapFont fnt = BitmapFontLoader.loadDefaultFont();
BitmapText txt = new BitmapText(fnt, false);
txt.setBox(new Rectangle(10, -10, game.getDisplay().getWidth() - 20,
game.getDisplay().getHeight() - 20));
txt.setSize(32);
txt.setDefaultColor(ColorRGBA.green.clone());
txt.setText(txtB);
txt.update();
int caseNumber = 3; // choose case 3
// case 1: render 2d text
if (caseNumber == 1) {
// works
Node orthoNode = new Node();
orthoNode.setLocalTranslation(0, game.getDisplay().getHeight(), 0);
orthoNode.setCullHint(CullHint.Never);
orthoNode.attachChild(txt);
debug.getRootNode().attachChild(orthoNode);
}
// case 2: render a quad at the same place where the text should be (0, 0, 0)
else if (caseNumber == 2) {
// works: seems to use the font texture by default
Quad quad = new Quad("quad", 5, 5);
quad.setModelBound(new BoundingBox());
quad.updateModelBound();
quad.setLocalTranslation(0, 0, 0);
debug.getRootNode().attachChild(quad);
}
// case 3: render the same text at (0, 0, 0) in 3D
else {
// won't show anything
txt.setLocalTranslation(0, 0, 0);
txt.updateModelBound();
txt.setModelBound(new BoundingBox());
debug.getRootNode().attachChild(txt);
}
return null;
}
});
}
}
System specs: Intel Core 2 Duo @ 2.13 GHz, 2 GB RAM, Geforce 7950 GX2, WinXP 32-bit