How do I draw a circle using OpenGL?

Started by
3 comments, last by CableGuy 16 years, 9 months ago
Hi there! I would like to know how do I draw a circle using OpenGL. Thanks in advance!
The future belongs to those who believe in the beauty of their dreams.
Advertisement
Either using a sprite or a line strip.

Hope this helps.
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;}
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();
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.

This topic is closed to new replies.

Advertisement