I want to draw a simple Circle with OpenGL in C#, but I only get this:
I tried the blend function, but it hasn't worked. My code:
public static void DrawCircle(float x, float y, float radius, Color4 c)
{
GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
GL.Begin(PrimitiveType.TriangleFan);
GL.Color4(c);
GL.Vertex2(x, y);
for (int i = 0; i < 360; i++)
{
GL.Vertex2(x + Math.Cos(i) * radius, y + Math.Sin(i) * radius);
}
GL.End();
GL.Disable(EnableCap.Blend);
}
If you want to draw a transparent circle, then you have to use an alpha channel less than 255, when you set GL.Color4
.
GL.Color4( red, green, blue, 127 ); // alpha = 127 for semi-transparent
But if you want to draw the contur of a circle, then you have to change the primitive type:
The primitive type PrimitiveType.TriangleFan
will draw an area. Use PrimitiveType.LineLoop
to draw a conture.
See PrimitiveType and OpenGL Primitive.