GL_LINE_LOOP

In the book that i have, the code below shows something that resembles a circle, but in the picture theres 8 points and in the code only 4. my question is, how do i find out the other coordinates to make something that looks as much as possible like a circle.

glBegin(GL_LINE_LOOP);
glVertex2f(-20,-20);
glVertex2f(-20,20);
glVertex2f( 20,20);
glVertex2f(20,-20);
glEnd();

glBegin(GL_LINE_LOOP);
for(float i=0; i<2pi; i++)
{
glVertex2f(20cos(i), 20sin(i));
}
glVertex2f(20,0);
glEnd();

something like that ought to do it.

Originally posted by chowe6685:
[b]glBegin(GL_LINE_LOOP);
for(float i=0; i<2pi; i++)
{
glVertex2f(20cos(i), 20sin(i));
}
glVertex2f(20,0);
glEnd();

something like that ought to do it.[/b]

Better make that for line as:
for(float i=0.f; i<2*PI; i+=PI/20.f)

/Alex

PS: 20.f is how much accuracy you want. Bigger values give better circles but you loose in speed. Experiment.

You don’t need that last glVertex (after the loop) because the line loop will automatically be closed. Had you used GL_LINE_STRIP, then the final glVertex call would be necessary.

thanks all i will give that a try. also something else, if i dont use a for loop instead use the vertex coordiantes, i will need atleast 8 or more points to make something that looks like a circle, how do i find those points?

You would still use sin/cos functions.

Originally posted by [TheFORCE]:
thanks all i will give that a try. also something else, if i dont use a for loop instead use the vertex coordiantes, i will need atleast 8 or more points to make something that looks like a circle, how do i find those points?