簡體   English   中英

OpenTK繪制透明圓

[英]OpenTK draw transparent Circle

我想在C#中用OpenGL繪制一個簡單的Circle,但是我只能得到這個:

IMG

我嘗試了blend函數,但是沒有用。 我的代碼:

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

如果要繪制透明圓,則在設置GL.Color4時必須使用小於255的alpha通道。

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


但是,如果要繪制圓的輪廓,則必須更改基本類型:

基本類型PrimitiveType.TriangleFan將繪制一個區域。 使用PrimitiveType.LineLoop繪制輪廓圖。
請參見PrimitiveTypeOpenGL Primitive

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM