This is a method I use to draw sprites:
public void DrawSprite(Sprite sprite)
{
Gl.glBegin(Gl.GL_TRIANGLES);
{
for (int i = 0; i < Sprite.VertexAmount; i++)
{
Gl.glBindTexture(Gl.GL_TEXTURE_2D, sprite.Texture.Id);
DrawImmediateModeVertex(
sprite.VertexPositions[i],
sprite.VertexColors[i],
sprite.VertexUVs[i]);
}
}
Gl.glEnd();
}
DrawImmediateModeVertex
- draws one vertex.
Should I get Gl.glBindTexture
out of the for loop? Also strange things happen when I render a texture, even开发者_如何学Go though i provide sprites with different texture ids, just one same texture is drawn every time.
From OpenGL documentation:
GL_INVALID_OPERATION is generated if glBindTexture is executed between the execution of glBegin and the corresponding execution of glEnd.
You should extract glBindTexture
outside glBegin
...glEnd
pair
Yes, move the bind outside of the loop, no need to repeatedly bind the same texture.
精彩评论