示例#1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Color4"/> class using values from another instance.
 /// </summary>
 /// <param name="color">A <see cref="Color4"/> instance.</param>
 public Color4(Color4 color)
 {
     _red	= color.R;
     _green	= color.G;
     _blue	= color.B;
     _alpha	= color.A;
 }
示例#2
0
 public Renderer()
 {
     loadedTextures = new Dictionary<string, int>();
     ClearColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f);
 }
示例#3
0
 protected void SetColor(Color4 color)
 {
     GL.Color4(color.R, color.G, color.B, color.A);
 }
示例#4
0
        // TODO: scale this correctly
        public void DrawVector2(Vector2 tail, Vector2 head, Color4 color)
        {
            Vector2 v = head - tail;
            v *= 2.0f;
            head = v + tail;

            Rotation2 rotation1 = new Rotation2(0.4f);
            Rotation2 rotation2 = new Rotation2(-0.4f);
            Vector2 dir1, dir2;
            dir1 = rotation1 * (tail - head) * 0.1f;
            dir2 = rotation2 * (tail - head) * 0.1f;

            SetColor(color);
            GL.Begin(PrimitiveType.Lines);
            GL.Vertex2(tail.X, tail.Y);
            GL.Vertex2(head.X, head.Y);

            GL.Vertex2(head.X, head.Y);
            GL.Vertex2(head.X + dir1.X, head.Y + dir1.Y);

            GL.Vertex2(head.X, head.Y);
            GL.Vertex2(head.X + dir2.X, head.Y + dir2.Y);

            GL.End();
        }
示例#5
0
 public void DrawLine(Vector2 A, Vector2 B, Color4 color)
 {
     SetColor(color);
     GL.Begin(PrimitiveType.Lines);
     GL.Vertex2(A.X, A.Y);
     GL.Vertex2(B.X, B.Y);
     GL.End();
 }
示例#6
0
        public void DrawCylinder(Vector2 A, Vector2 B, float radius, Color4 fillColor, Color4 outlineColor)
        {
            Vector2 AB = B - A;
            float ang0 = (float)System.Math.Atan2(AB.Y, AB.X) + (float)MathFunctions.PI / 2.0f;

            const float N = 8;

            if (fillColor.A > 0.0f)
            {
                SetColor(fillColor);
                GL.Begin(PrimitiveType.TriangleFan);
                for (int n = 0; n <= N; n++)
                {
                    float f = ang0 + ((float)n / (float)N) * (float)MathFunctions.PI;
                    Vector2 v = A + radius * new Vector2((float)MathFunctions.Cos(f), (float)MathFunctions.Sin(f));
                    GL.Vertex2(v.X, v.Y);
                }
                for (int n = 0; n <= N; n++)
                {
                    float f = ang0 + (float)MathFunctions.PI + ((float)n / (float)N) * (float)MathFunctions.PI;
                    Vector2 v = B + radius * new Vector2((float)MathFunctions.Cos(f), (float)MathFunctions.Sin(f));
                    GL.Vertex2(v.X, v.Y);
                }
                GL.End();

            }

            if (outlineColor.A > 0.0f)
            {
                SetColor(outlineColor);
                GL.Begin(PrimitiveType.LineLoop);
                for (int n = 0; n <= N; n++)
                {
                    float f = ang0 + ((float)n / (float)N) * (float)MathFunctions.PI;
                    Vector2 v = A + radius * new Vector2((float)MathFunctions.Cos(f), (float)MathFunctions.Sin(f));
                    GL.Vertex2(v.X, v.Y);
                }
                for (int n = 0; n <= N; n++)
                {
                    float f = ang0 + (float)MathFunctions.PI + ((float)n / (float)N) * (float)MathFunctions.PI;
                    Vector2 v = B + radius * new Vector2((float)MathFunctions.Cos(f), (float)MathFunctions.Sin(f));
                    GL.Vertex2(v.X, v.Y);
                }
                GL.End();
            }
        }
示例#7
0
        public void DrawCircle(Vector2 center, float radius, Color4 fillColor, Color4 outlineColor)
        {
            const int numCircleVerts = 16;

            if (fillColor.A > 0.0f)
            {
                SetColor(fillColor);
                GL.Begin(PrimitiveType.TriangleFan);
                for (int i = 0; i < numCircleVerts; i++)
                {
                    Vector2 v = center + radius * new Vector2((float)MathFunctions.Cos(2.0f * MathFunctions.PI * (float)i / (float)numCircleVerts), (float)MathFunctions.Sin(2.0f * MathFunctions.PI * (float)i / (float)numCircleVerts));
                    GL.Vertex2(v.X, v.Y);
                }
                GL.End();
            }

            if (outlineColor.A > 0.0f)
            {
                SetColor(outlineColor);
                GL.Begin(PrimitiveType.LineLoop);
                for (int i = 0; i < numCircleVerts; i++)
                {
                    Vector2 v = center + radius * new Vector2((float)MathFunctions.Cos(2.0f * MathFunctions.PI * (float)i / (float)numCircleVerts), (float)MathFunctions.Sin(2.0f * MathFunctions.PI * (float)i / (float)numCircleVerts));
                    GL.Vertex2(v.X, v.Y);
                }
                GL.End();
            }
        }
示例#8
0
        public void DrawBox(Box2 box, Color4 fillColor, Color4 outlineColor)
        {
            if (fillColor.A > 0.0f)
            {
                SetColor(fillColor);
                GL.Begin(PrimitiveType.Quads);

                GL.Vertex2(box.Left, box.Bottom);
                GL.Vertex2(box.Right, box.Bottom);
                GL.Vertex2(box.Right, box.Top);
                GL.Vertex2(box.Left, box.Top);

                GL.End();
            }

            if (outlineColor.A > 0.0f)
            {
                SetColor(outlineColor);
                GL.Begin(PrimitiveType.LineLoop);

                GL.Vertex2(box.Left, box.Bottom);
                GL.Vertex2(box.Right, box.Bottom);
                GL.Vertex2(box.Right, box.Top);
                GL.Vertex2(box.Left, box.Top);

                GL.End();
            }
        }
示例#9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Color4"/> class from a blend of two colors.
 /// </summary>
 /// <param name="source">The blend source color.</param>
 /// <param name="dest">The blend destination color.</param>
 /// <param name="opacity">The opacity value.</param>
 public Color4(Color4 source, Color4 dest, float opacity)
 {
     _red	= MathFunctions.LinearInterpolation(source.R, dest.R, opacity);
     _green	= MathFunctions.LinearInterpolation(source.G, dest.G, opacity);
     _blue	= MathFunctions.LinearInterpolation(source.B, dest.B, opacity);
 }
示例#10
-1
        public void DrawTexturedQuad(int TextureID, Box2 Box, Color4 color, bool flipX)
        {
            SetColor(color);
            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.BindTexture(TextureTarget.Texture2D, TextureID);

            GL.Begin(PrimitiveType.Quads);
            if (!flipX)
            {
                GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(Box.Left, Box.Bottom);
                GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(Box.Right, Box.Bottom);
                GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(Box.Right, Box.Top);
                GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(Box.Left, Box.Top);
            }
            else
            {
                GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(Box.Left, Box.Bottom);
                GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(Box.Right, Box.Bottom);
                GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(Box.Right, Box.Top);
                GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(Box.Left, Box.Top);
            }
            GL.End();

            GL.BindTexture(TextureTarget.Texture2D, 0);
        }