Advertisement

How to draw a circle?

Started by January 06, 2003 06:08 PM
3 comments, last by Pontius 22 years, 1 month ago
I was wondering how you would draw a 2d circle in openGL since there is no built in function to do it. I want to be able to specify a radius, I''ve seen some examples that draw a fixed size circle, but none able to specify a radius. I want something like DrawCircle(double radius) { glBegin(GL_POLYGON) for(...) { //..... } glEnd(); }
for (i=0;i<360;i++)
{
x = radius_x * cos(i*3.14/180);
y = radius_y * sin(i*3.14/180);
DrawPixel(x,y);
}

I don''t remember exactly, but I think it''s the correct way.


Flamewars don''t make you look smart, but idiot.
Advertisement
quote:
Original post by Pontius
I was wondering how you would draw a 2d circle in openGL since there is no built in function to do it. I want to be able to specify a radius, I've seen some examples that draw a fixed size circle, but none able to specify a radius. I want something like

DrawCircle(double radius)
{

glBegin(GL_POLYGON)
for(...)
{
//.....
}
glEnd();
}




you can your glu functions ...

GLUquadricObj *Circle;
Circle = gluNewQuadric ();

gluDisk (Circle,innerRadius,outerRadius,slices,loops) ;
...
here is the definition of gluDisk :

then use gluDeleteQuadric to destroy the object




[edited by - Metal Typhoon on January 6, 2003 7:18:30 PM]
Metal Typhoon
if you want to alter the resolution of the circle, change i++ to i+=2 for half the resolution, or i+=6 for a point every 30 degrees, using this you can create regular polygons in one easy fuunction.

"Very funny, Scotty. Now beam down my clothes."

Twitter: [twitter]CaffinePwrdAl[/twitter]

Website: (Closed for maintainance and god knows what else)

Thanks, here it is, this works fine if anyone needs it


void DrawCircle(double Radius, int Edges)
{
GLfloat x, y, temp;
glBegin(GL_POLYGON);
temp = 360.0 / (float)Edges;
for(float i = 0; i < 360; i+=temp)
{
x = Radius * cos(i * PI / 180.0f);
y = Radius * sin(i * PI / 180.0f);

glVertex2f(x, y);
}
glEnd();
}

This topic is closed to new replies.

Advertisement