Exemplo n.º 1
0
        public static void Draw(BTexture texture, Vector2 position, Vector2 scale, Color colorOverlay, Vector2 origin, RectangleF?sourceRec = null)
        {
            Vector2[] vertices = new Vector2[4]
            {
                new Vector2(0, 0),
                new Vector2(1, 0),
                new Vector2(1, 1),
                new Vector2(0, 1),
            };

            GL.BindTexture(TextureTarget.Texture2D, texture.ID);
            GL.Begin(PrimitiveType.Quads);

            GL.Color3(colorOverlay);
            for (int i = 0; i < 4; i++)
            {
                if (sourceRec == null)
                {
                    GL.TexCoord2(vertices[i].X, vertices[i].Y);
                }
                else
                {
                    GL.TexCoord2((sourceRec.Value.Left + vertices[i].X * sourceRec.Value.Width) / texture.Width,
                                 (sourceRec.Value.Top + vertices[i].Y * sourceRec.Value.Height) / texture.Height);
                }

                vertices[i].X *= (sourceRec == null) ? texture.Width : sourceRec.Value.Width;
                vertices[i].Y *= (sourceRec == null) ? texture.Height : sourceRec.Value.Height;
                vertices[i]   -= origin;
                vertices[i]   *= scale;
                vertices[i]   += position;

                GL.Vertex2(vertices[i].X, vertices[i].Y);
            }

            GL.End();
        }