问题
I want to render a BitmapFont within a libgdx ModelBatch. I've only found samples with "SpriteBatch". Of course I can move the SpriteBatch around in 3D space, but it is either rendered before or after the "ModelBatched" objects. But I'd like to have it rendered in the correct z position.
E.g.
- Render modelInstanceA (z=20)
- Render Font (z=30)
- Render modelInstanceB (z=40)
Then modelInstanceB should cover Render Font should cover modelInstanceB.
In other words I'd like to render a font within a ModelBatch context.
modelBatch.begin(camera);
modelBatch.render(modelInstanceA);
modelBatch.render(font);
modelBatch.render(modelInstanceB);
modelBatch.end();
Is there a built in way to achieve this?
回答1:
If the models are opaque, you could draw your text with SpriteBatch after the modelBatch.end()
call, but you'd need to call Gdx.gl.glEnable(GL20.GL_DEPTH_TEST); before spriteBatch.begin()
. Then disable it after spriteBatch.end()
to clean up (libgdx classes by default expect it to be off).
来源:https://stackoverflow.com/questions/32567900/render-bitmapfont-in-3d-libgdx-with-modelbatch