libgdx decal dynamic text

ε祈祈猫儿з 提交于 2019-12-20 05:46:07

问题


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!


回答1:


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();



回答2:


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.



来源:https://stackoverflow.com/questions/24375179/libgdx-decal-dynamic-text

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!