# Solid circle with OpenGL

I’m trying to make a simple pong game with modern OpenGL (made pong game before, but not with modern OpenGL). I’m starting out with trying to to draw a ball onto the screen with a simple solid red shader. However, this confuses me because OpenGL draws triangles, not circles. The closest thing I found to a circle used immediate mode and didn’t fill it in. What should I use to draw a circle?

I don’t use modern GL, so I’m not sure this suggestion will work for you.

If it was me (old guy - old GL), I’d use a large, anti-aliased point.
Triangles or polygons of any kind would not be necessary.

You couldn’t draw a circle in fixed function GL either.

There are multiple things that you could do to get circles:

[ul]
[li] Draw a triangle fan.[/li][li] Draw a rectangle out of two triangles with an image of a circle texture-mapped onto it.[/li][li] Draw a rectangle out of two triangles and use the fragment shader to cut away the fragments that are further away from the center than the circle radius.[/li][li] Draw a huge, anti-aliased point.[/li][/ul]

void drawCircle(GLfloat x, GLfloat y, GLfloat radius)
{
int i;
int triangleAmount = 1000;
GLfloat twicePi = 2.0f * PI;

``````    glEnable(GL_LINE_SMOOTH);
glLineWidth(5.0);

glBegin(GL_LINES);
glColor4f(1.0, 0.0, 0.0, 1.0);
for(i = 0; i &lt;= triangleAmount; i++)
{
glVertex2f( x, y);
glVertex2f(x + (radius * cos(i * twicePi / triangleAmount)), y + (radius * sin(i * twicePi / triangleAmount)));
}
glEnd();
``````

}

Try this function.

muthuveera, you might want to re-read the original post that startet this thread.

The function you pasted here uses deprecated glBegin/glColor/glVertex/glEnd calls and the circle it produces is only an outline and not solid.

The post at the top explicitly asks for how to draw a solid circle using modern OpenGL®.

Sry, i hav used only open gl 1.3 version. Anyhw it will create the solid circle. In this I was using lines not a line strip. In this way only i got a perfect circle instead of using triangle fan.