OpenTK绘制透明圆

时间:2017-09-09 11:57:14

标签: c# opengl transparency geometry opentk

我想在C#中使用OpenGL绘制一个简单的Circle,但我只能得到这个:

img

我尝试了混合功能,但它没有奏效。 我的代码:

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);
    }

1 个答案:

答案 0 :(得分:0)

如果要绘制透明圆圈,则在设置GL.Color4时必须使用小于255的Alpha通道。

GL.Color4( red, green, blue, 127 ); // alpha = 127 for semi-transparent 


但是如果要绘制圆的轮廓,则必须更改基本类型:

原始类型PrimitiveType.TriangleFan将绘制一个区域。使用PrimitiveType.LineLoop绘制一个绷带 请参阅PrimitiveTypeOpenGL Primitive