public static void DrawSprite(uint texId, Rectangle rect, Matrix4 mat, float[] texCoords, Vector4 colorScale) { float x = rect.X; float y = rect.Y; float width = rect.Width; float height = rect.Height; float[] Vertices = { x + width, y, x + width, y + height, x, y, x, y + height }; if (texCoords == null) { float[] tx = { 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f }; texCoords = tx; } GLHelper.GetError(); TextureShader shader = TextureShader.Singleton; // Use shader GL.UseProgram(shader.mProgram); shader.SetColorScale(colorScale); // Set texture GL.ActiveTexture(TextureUnit.Texture0); // Set active texture slot to 0 GL.BindTexture(TextureTarget.Texture2D, texId); // Bind 2D texture to current slot GL.Uniform1(shader.muTextureHandle, 0); // Set shader sampler to texture slot 0 // Set Model view GL.UniformMatrix4(shader.muMVPMatrixHandle, 1, false, ref mat.Row0.X); // Set vertex and texture coords GL.EnableVertexAttribArray(shader.maPositionHandle); GL.EnableVertexAttribArray(shader.maTexCoordHandle); GL.VertexAttribPointer(shader.maPositionHandle, 2, VertexAttribPointerType.Float, false, 0, Vertices); GL.VertexAttribPointer(shader.maTexCoordHandle, 2, VertexAttribPointerType.Float, false, 0, texCoords); GL.DrawArrays(BeginMode.TriangleStrip, 0, 4); GL.DisableVertexAttribArray(shader.maPositionHandle); GL.DisableVertexAttribArray(shader.maTexCoordHandle); GLHelper.GetError(); }
// TODO: find better way to access shaders public static void Reset() { singleton = null; }