Rendering Text on a Box

Not sure if i should go take another powernap.



Can text be rendered in modes other than ortho





Simple code attached, all i get is the font map, the text isnt rendered





import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.scene.Text;
import com.jme.scene.shape.Box;
import com.jme.scene.state.LightState;
import com.jme.scene.state.RenderState;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;


public class TestSign extends SimpleGame{

String text;
Text fps;
public TestSign(String text) {
this.text = text;
}

public void simpleInitGame() {

Box sign = new Box("sign", new Vector3f(-1.5f,0f ,0f), new Vector3f(1.5f ,2,.01f));
sign.setModelBound(new BoundingBox());
sign.setDefaultColor(ColorRGBA.blue);
sign.setLightCombineMode(LightState.OFF);
sign.setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);

fps = Text.createDefaultTextLabel(text);
    fps.setCullMode(Spatial.CULL_NEVER);
    fps.setTextureCombineMode(TextureState.REPLACE);    
    TextureState ts2 = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
Texture t2 = TextureManager.loadTexture(ImageBase.class.getClassLoader().getResource("font.png"), Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR);
ts2.setTexture(t2);
fps.setRenderState(ts2);
   
Node node = new Node("signNode");

node.setRenderState(fps.getRenderState(RenderState.RS_ALPHA));
node. setRenderState(fps.getRenderState(RenderState.RS_TEXTURE));
node.attachChild(fps);
node.attachChild(sign);
node.setCullMode(Spatial.CULL_NEVER);
node.updateGeometricState(0.0f, true);
node.updateRenderState();

rootNode.attachChild(node);
}
public static void main(String[] args) {
TestSign app = new TestSign("yehaaaaa");
    app.setDialogBehaviour(NEVER_SHOW_PROPS_DIALOG);
    app.start();

  }
}

The Text class renders directly to the buffer so you cannot use it as texture. But you have other choices:

  1. use Text and render to texture, then apply the rendered texture to whatever you like
  2. use ImageGraphics to draw a text via awt, update a texture with it and apply that to your geom. This has the advantage/drawback that system fonts can/must be used.
  3. use JMEDesktop with a JTextArea or JEditorPane (you can even use simple HTML then) - but that could be too much overhead

Thanks irrisor



You are top !!!