我正在使用 libgdx 为 Android 编写游戏。下面是一些绘制带纹理环面的代码:
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() 调用了 glDisable(GL_TEXTURE_2D)。只需要阅读源代码...
最佳答案
它实际上在 Javadocs 中也是这样说的。经验法则:连接到 OpenGL ES 的所有 libgdx 类都会更改最少的状态,并且很可能不会重置事物,因为查询 GL 的状态成本很高。
关于java - 为什么 libgdx SpriteBatch/BitmapFont 会破坏 Texture.bind?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7328376/