سؤال

I'm writing a game for Android using libgdx. Here is some code that draws a textured torus:

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();

...and here is some code that draws a bit of text:

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

The first bit of code works, frame after frame, until the second bit of code runs. After that, the first bit's triangle strip is rendered using only the latest glMaterial. Any idea why this is happening?

Update: Solved! It turns out SpriteBatch.end() calls glDisable(GL_TEXTURE_2D). Just had to read the source...

هل كانت مفيدة؟

المحلول

It actually says so in the Javadocs as well. Rule of thumb: all libgdx classes connected to OpenGL ES will change the minimum amount of states and most likely won't reset things as querying GL for state is costly.

نصائح أخرى

I ran into the same problem and my solution was to set the active texture back to GL_TEXTURE0 before letting SpriteBatch (or in my case scene2d) do its stuff:

Gdx.gl20.glActiveTexture(GL20.GL_TEXTURE0);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top