Reputation: 21
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 though i provide sprites with different texture ids, just one same texture is drawn every time.
Upvotes: 2
Views: 911
Reputation: 21435
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
Upvotes: 6
Reputation: 59
Yes, move the bind outside of the loop, no need to repeatedly bind the same texture.
Upvotes: 0