View Full Version : Solid circle with OpenGL

02-06-2015, 12:58 PM
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?

02-06-2015, 02:36 PM
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.

Agent D
02-07-2015, 10:05 AM
You couldn't draw a circle in fixed function GL either.

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

Draw a triangle fan.
Draw a rectangle out of two triangles with an image of a circle texture-mapped onto it.
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.
Draw a huge, anti-aliased point.

02-21-2015, 04:33 AM
void drawCircle(GLfloat x, GLfloat y, GLfloat radius)
int i;
int triangleAmount = 1000;
GLfloat twicePi = 2.0f * PI;


glColor4f(1.0, 0.0, 0.0, 1.0);
for(i = 0; i <= triangleAmount; i++)
glVertex2f( x, y);
glVertex2f(x + (radius * cos(i * twicePi / triangleAmount)), y + (radius * sin(i * twicePi / triangleAmount)));

Try this function.

Agent D
02-21-2015, 05:10 AM
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(R).

02-23-2015, 08:04 PM
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.