# OpenGL How do I draw a circle using OpenGL?

This topic is 4164 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi there! I would like to know how do I draw a circle using OpenGL. Thanks in advance!

##### Share on other sites
Either using a sprite or a line strip.

Hope this helps.

##### Share on other sites
Let rad be the radius of the n-gon and c the number of sides then.
float ad=(float)(2.0f*PI)/(float)c;float a=0;for (int i=0;i<c;i++;a+=ad;){	xOfNewPoint=cos(a)*rad;        yOfNewPoint=sin(a)*rad;}

##### Share on other sites
That's not legal C, CableGuy. You need to have a comma separating the i++ and the a+=ad. Not to mention, you could use much more descriptive variable names:

int numSides = whateverYouWant;float currentAngle = 0.0f;float deltaAngle= 2.0f*PI / float(numSides); //Difference between each pointglBegin(GL_POLYGON);for( int i = 0; i < numSides; i++ )//Could just have incremented currentAngle until it was >= 2*PI, but this works too{  currentAngle += deltaAngle; //I like this better in here than in the for(). Just aesthetics  //Gives the Polygon a new vertex  glVertex2f( cos(currentAngle), sin(currentAngle) );}glEnd();

##### Share on other sites
Yeah at first the currentAngle += deltaAngle; was in the for loop but then
I moved it to the for line don't know why, because of that I did the ;, mistake.

And yeah I just copied the code from some old 2d simulator. So the variables' names are a bit hacky.

1. 1
2. 2
3. 3
Rutin
23
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 11
• ### Forum Statistics

• Total Topics
633653
• Total Posts
3013157
×