PDA

View Full Version : GL_LINE_LOOP

[TheFORCE]
11-16-2003, 05:19 AM
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();

chowe6685
11-16-2003, 06:56 AM
glBegin(GL_LINE_LOOP);
for(float i=0; i<2pi; i++)
{
glVertex2f(20*cos(i), 20*sin(i));
}
glVertex2f(20,0);
glEnd();

something like that ought to do it.

Alex71
11-16-2003, 10:22 AM
Originally posted by chowe6685:
glBegin(GL_LINE_LOOP);
for(float i=0; i<2pi; i++)
{
glVertex2f(20*cos(i), 20*sin(i));
}
glVertex2f(20,0);
glEnd();

something like that ought to do it.

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.

Eric Lengyel
11-17-2003, 09:26 PM
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.

[TheFORCE]
11-18-2003, 08:41 AM
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?

nexusone
11-18-2003, 10:23 AM
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?