我正在使用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)。只需要查看源代码即可...