开发者

Question about glBindTexture

开发者 https://www.devze.com 2023-03-27 00:42 出处:网络
This is a method I use to draw sprites: public void DrawSprite(Sprite sprite) { Gl.glBegin(Gl.GL_TRIANGLES);

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消