How 2 draw a circle

Hello,
I am doing my project now…wat i need 2 do now is wanna drawing a simple circle…who can tell me how should i draw a circle with a GL_LINE_LOOP or GL_POLYGON…??

Thank you.

Hi !

With GL_LINE_LOOP you will get a circle, with GL_POLYGON you break down the “circle” into triangles, so if you just want a circle, use GL_LINE_LOOP if you intend to fill it with color or texture then use GL_POLYGON (a disk).

Mikael

play with this:

GLfloat r = 1.;

glBegin(GL_LINE_LOOP);

for(float phi = 0; phi <= 2*M_PI; phi += M_PI/10.)
  glVertex3f(r*cos(phi), r*sin(phi), 0.);

glEnd();

Originally posted by GreetingsFromMunich:
[b]play with this:

GLfloat r = 1.;

glBegin(GL_LINE_LOOP);

for(float phi = 0; phi <= 2M_PI; phi += M_PI/10.)
glVertex3f(r
cos(phi), r*sin(phi), 0.);

glEnd();

[/b]

hello,I am also a beginner,I am thinking if do like that,would i gain a circle not filled?
3Q

Yes, you will get lines, that’s the idea with GL_LINE_LOOP, if you replace GL_LINE_LOOP with GL_POLYGON you will get a filled circle instead (if you have setup the correct polygon mode).

Mikael

for a filled circle i’d rather use a triangle fan than a polygon:

GLfloat r = 1.;

glBegin(GL_TRIANGLE_FAN);

glVertex3f(0., 0., 0.);

for(float phi = 0; phi <= 2*M_PI; phi += M_PI/10.)
  glVertex3f(r*cos(phi), r*sin(phi), 0.);

glEnd();

the first vertex defines the center, the vertices in the for-loop lie on the perimeter

Originally posted by mikael_aronsson:
[b]Yes, you will get lines, that’s the idea with GL_LINE_LOOP, if you replace GL_LINE_LOOP with GL_POLYGON you will get a filled circle instead (if you have setup the correct polygon mode).

Mikael[/b]
Thank you very much