简体   繁体   中英

OpenTK draw transparent Circle

I want to draw a simple Circle with OpenGL in C#, but I only get this:

IMG

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM