I'm working on 3D (2.5D) application in Libgdx.
I've found Decals very useful for this purpose.
In my app there should be layers, that contain dynamical text, now I'm wondering what is the best way to draw text via Decals.
Currently my implementation is based on drawing BitmapFont to FBO, then I get FBO texture and bind it to Decal before DecalBatch.flush().
I think that this is maybe not the most efficient way of doing this, but can't figure out better way.
My app can contain large number of text "layers" placed into 3D world, so maybe drawing each BitmapFont to FBO, and binding FBO texture to Decal isn't the best approach.
Do you guys have some better idea?
What is the most efficient way of doing this?
Tnx in advance!
You can draw directly into 3D space with SpriteBatch by assigning your projection matrix appropriately.
First, have a Matrix4 that determines the position and rotation of each of your strings of text. The reason you need this is that SpriteBatch and BitmapFont do not have arguments for Z offset.
Since you can put all your translation into the Matrix4, when you call the draw
method, just draw to 0,0.
You can then use the Matrix4 of each mesh to multiply with the camera's combined matrix before submitting it to the SpriteBatch. So you will want a separate Matrix4 for doing your calculations.
textTransform.idt().scl(0.2f).rotate(0, 0, 1, 45).translate(-50, 2, 25f);
//Probably need to scale it down. Scale before moving or rotating.
spriteBatch.setProjectionMatrix(tmpMat4.set(camera.combined).mul(textTransform));
spriteBatch.begin();
font.draw(spriteBatch, "Testing 1 2 3", 0, 0);
spriteBatch.end();
To get the rotation behaviour of Decals you need to call translate first before rotate on the textTransform Matrix.
textTransform.idt().translate(-50, 2, 25f).rotate(0, 0, 1, 45);
I'm a little confused about this. Maybe its historically reasoned from a Matrix Stack.