PDA

View Full Version : How 2 draw a circle



efang
12-19-2004, 11:19 AM
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.

mikael_aronsson
12-19-2004, 09:43 PM
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

RigidBody
12-20-2004, 09:55 AM
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();

MyPinLost
12-21-2004, 09:01 PM
Originally posted by GreetingsFromMunich:
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();hello,I am also a beginner,I am thinking if do like that,would i gain a circle not filled?
3Q

mikael_aronsson
12-21-2004, 11:16 PM
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

RigidBody
12-21-2004, 11:21 PM
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

MyPinLost
12-24-2004, 08:59 PM
Originally posted by mikael_aronsson:
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).

MikaelThank you very much