Search code examples
openglopentk

Drawing smooth circle


I'm using OpenTK (C#) but OpenGL suggestions are welcome too.

I have a point list generated by iteration having 1 degrees per point around the center point which means there are 361 point including the center point. Point list can be different with different approaches, that's ok. I can draw the circle with the below simple Vertex and Fragment shaders. How can change the fragment and/or vertex shaders to have a smooth circle.

Vertex shader:

#version 330
in  vec3 vPosition;
in  vec4 vColor;
out vec4 color;
out vec4 fPosition;
uniform mat4 modelview;
void main()
{
    fPosition = modelview * vec4(vPosition, 1.0);
    gl_Position = fPosition;
    color = vColor;
}

Fragment shader:

#version 330
in vec4 color;
in vec4 fPosition;
out vec4 outputColor;
void main()
{
    outputColor = color;
}

C# code:

GL.DrawArrays(PrimitiveType.TriangleFan, 0, points.Length);

Solution

  • Hello what do you actually see ? Post a screenshot. Anyway for smooth edges we have what's called anti alising. Use this line for your glControl to enable it

    glControl = new GLControl(new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8));