Jump to content
  • Advertisement
Sign in to follow this  
Zdravko

OpenGL How do I draw a circle using OpenGL?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
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 this post


Link to post
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 point

glBegin(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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!