# 30. OpenGL Circle Drawing

Here we are going to create a circle. This is something I don’t believe
you can do unless you create it on your own. In other words, it is not
preset.

Now because a circle is just a bunch of lines. That is what we are going
to make. A bunch of lines, close together that go around in a circle.

Now first of all I am going to create a typedef to hold our circle properties
as we call them

typedef struct
{

This will hold the x values as we need them
float x;
This will hold the y values as we need them
float y;
Call it CIRCLE
}CIRCLE;

Then I am setting the property circle to act like the typedef CIRCLE
CIRCLE circle;

Now for the meat of this tutorial, the circle creation function
The properties this takes are:
k – the translation on the y axis
r – the radius of the circle
h – the translation on the x axis

void createcircle (int k, int r, int h) {
Now we begin drawing our lines
glBegin(GL_LINES);
Here we are setting up the vertices all in one line function, this
sets every 2 vertices to a line.

First we begin our loop, this loop will cycle through, constantly
changing our x and y values for our lines. It cycles through until
it reaches 180, increasing in intervals of 1
for (int i = 0;i < 180;i++)
{

Now to set up the current x value that we need for our vertex
I am setting it to the radius of the circle, times by the cosine of
the current value of i, then I am taking h to translate it
circle.x = r * cos(i) – h;
Then to set up the current y value that we need for our vertex
I am setting it to the radius of the circle, times by the sine of
the current value of i, then I am adding k to translate it
circle.y = r * sin(i) + k;
Then I am drawing the vertex
glVertex3f(circle.x + k,circle.y – h,0);

Now for the second part of the line, I am doing the same as above, only
I am moving it 0.1 units so that I am not down to points. This also
Lowers the chance of any holes occuring in the circle
circle.x = r * cos(i + 0.1) – h;
circle.y = r * sin(i + 0.1) + k;

Then I am drawing the vertex
glVertex3f(circle.x + k,circle.y – h,0);
}
glEnd();
}

Then to call it, use something like this:
createcircle(0,10,0);

That would create a circle that is originated around (0,0) and with