Hi,
I’m trying to create a terminal screen in my little test game where I want to be able to print text. (Inspired by Notch/Mojang game 0x10c and the DCPU-16)
I have been looking at the render to texture example and I now have a black flattened cube that I can get a box on. However, when I try to attach a BitmapText instead it’s never shown. I must have overlooked something. Can anyone spot what it is I’m doing wrong?
Also: Is there a better way to create a text terminal in JME3? Can I manipulate the texture directly or something?
The setup code I have at the moment for the render to texture:
[java]
public Texture setupOffscreenView( AssetManager assetManager, RenderManager renderManager ) {
int w = 128,h=128;
Camera offCamera = new Camera(w, h);
offView = renderManager.createPreView(“Offscreen View”, offCamera);
offView.setClearFlags(true, true, true);
offView.setBackgroundColor(ColorRGBA.Black);
// create offscreen framebuffer
FrameBuffer offBuffer = new FrameBuffer(w, h, 1);
//setup framebuffer’s cam
offCamera.setFrustumPerspective(45f, 1f, 1f, 1000f);
offCamera.setLocation(new Vector3f(0f, 0f, -5f));
offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);
//setup framebuffer’s texture
Texture2D offTex = new Texture2D(w, h, Image.Format.RGBA8);
offTex.setMinFilter(Texture.MinFilter.NearestNoMipMaps);
offTex.setMagFilter(Texture.MagFilter.Nearest);
//setup framebuffer to use texture
offBuffer.setDepthBuffer(Image.Format.Depth);
offBuffer.setColorTexture(offTex);
//set viewport to render to offscreen framebuffer
offView.setOutputFrameBuffer(offBuffer);
// setup framebuffer’s scene
node = new Node();
// Works just great:
Box boxMesh = new Box(Vector3f.ZERO, 0.3f,0.3f,0.3f);
Material material = assetManager.loadMaterial(“Interface/Logo/Logo.j3m”);
Geometry offBox = new Geometry(“box”, boxMesh);
offBox.setMaterial(material);
offBox.rotate(0,45*FastMath.DEG_TO_RAD,0);
node.attachChild(offBox);
// Not shown:
BitmapFont fnt = assetManager.loadFont(“Interface/Fonts/Default.fnt”);
BitmapText txt = new BitmapText(fnt, false);
txt.setColor(ColorRGBA.Green);
txt.setQueueBucket(RenderQueue.Bucket.Opaque);
txt.setSize(0.5f);
txt.setText(“Ready>”);
txt.setLocalTranslation( Vector3f.ZERO );
node.attachChild( txt );
offView.attachScene(node);
node.updateGeometricState();
return offTex;
}
[/java]
Nifty would be the obvious solution, I seem to remember it even has a console control.
Failing that you could use either BitmapText or ImagePainter…
I haven’t been able to get BitmapText to work.
Will take a look at that ImagePainter thingy.
Nifty might work, but it feels a bit overkill to use it just for a text terminal. But will take a quick look at it none the less.
Thanks.
Yeah, there is a nifty control ‘nifty-console’. Like zarch said nifty seems to be the approach.
But actually the ‘nifty-console’ control fails; failing text selecting, focus losing etc; still some work to do
Currently playing around with this, and it looks promising. With some work and a bit of luck I might even be able to support programmable font characters like the “real” DCPU-16 does.
Haven’t looked at Nifty yet. But having text selecting and focus and what not is not needed here, as all I want is to write some text on to a texture.
http://hub.jmonkeyengine.org/groups/contribution-depot-jme3/forum/topic/image-getpixelsetpixel-imagepainter-editing-jme3-images/
That’s ImagePainter. It’s not properly integrated into the core though due to some…complications…
Thanks, will try it out.
Actually the bitmap text works fine in texturerenderer, the whole gui i use is renderd to a texture and overlayed over the main scene, and I heavly use bitmaptext
I went with the route I started yesterday using the code I linked to. It didn’t take long until I had letters all over the screen. It was fun coding it.
It even responds to keypresses! Now to decide if I should write my own simple and not very realistic CPU architecture, for the lols, or if I should steal borrow the DCPU specs from 0x10c.
Thanks for the help and suggestions!