簡體   English   中英

如何避免libgdx SpriteBatch / BitmapFont破壞Texture.bind?

[英]How can I avoid libgdx SpriteBatch/BitmapFont breaking Texture.bind?

Gdx.gl10.glPushMatrix();
Gdx.gl10.glTranslatef(center.x, center.y, 0);
Gdx.gl10.glRotatef(0, 0, 1, angle * 360f / (2f * (float)Math.PI));
texture.bind();
mesh.render(GL10.GL_TRIANGLE_STRIP);
Gdx.gl10.glPopMatrix();

...這里有一些代碼可以繪制一些文字:

spriteBatch.begin();
spriteBatch.setColor(1, 1, 1, 1);
float fps = 1f / Gdx.graphics.getDeltaTime();
font.draw(spriteBatch, "fps: " + fps, 0, 50);
spriteBatch.end();

第一位代碼一幀一幀地工作,直到第二位代碼運行。 之后,第一位的三角形條帶僅使用最新的glMaterial渲染。 知道為什么會這樣嗎? 我應該怎么做才能將兩種材質保持在繪圖中(網格及其精靈紋理的'紋理',應該是不同的)?

SpriteBatch#end()有禁止混合和紋理,因為它假定在呼叫干凈GL狀態上下文SpriteBatch#begin()和還原的清潔狀態上下文SpriteBatch#end() 在您的情況下,您只需在渲染網格之前通過glEnable(GL10.GL_TEXTURE_2D)啟用紋理。

如有疑問,請查看SpriteBatch javadocs,它會告訴您它所做的GL狀態更改。

我遇到了同樣的問題,我的解決方案是將活動紋理設置回GL_TEXTURE0,然后讓SpriteBatch(或者在我的情況下為scene2d)做它的東西:

Gdx.gl20.glActiveTexture(GL20.GL_TEXTURE0);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM