问题描述
我想在libgdx ModelBatch中渲染一个BitmapFont.我只发现了带有"SpriteBatch"的样本.当然,我可以在3D空间中移动SpriteBatch,但是它可以在"ModelBatched"对象之前或之后渲染.但我想将其渲染到正确的z位置.
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.
例如
- 渲染modelInstanceA(z = 20)
- 渲染字体(z = 30)
- 渲染modelInstanceB(z = 40)
然后,modelInstanceB应该覆盖Render字体应该覆盖modelInstanceB.
Then modelInstanceB should cover Render Font should cover modelInstanceB.
换句话说,我想在ModelBatch上下文中渲染字体.
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?
推荐答案
如果模型不透明,则可以在modelBatch.end()
调用之后使用SpriteBatch绘制文本,但是您需要调用Gdx.gl.glEnable( GL20.GL_DEPTH_TEST);在spriteBatch.begin()
之前.然后在spriteBatch.end()
之后将其禁用以进行清理(默认情况下,libgdx类希望将其关闭).
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).
这篇关于使用ModelBatch在3D libgdx中渲染BitmapFont的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!