# Drawing a circle using glut...

• 10-17-2004
bennyho03
Drawing a circle using glut...
I can't seem to draw a circle using glut... anybody knows how to do it... thanx in advance. I think i know the logic and that is to split the circle into individual small lines and outputting them...
• 10-17-2004
bennyho03
My original code is this
PHP Code:

``` void function(void){     float calculate (float);     float x,y;     int i;     glClearColor(1.0, 0.0, 1.0, 0.0);         glClear(GL_COLOR_BUFFER_BIT);                   /*Draw axes*/     glColor3f(1.0,1.0,1.0);        //black color     glLineWidth(5); //5 pixels     /*Perform drawing of axes*/     glBegin(GL_LINES);     glVertex2f(0,1);     glVertex2f(0,-1);     glVertex2f(1,0);     glVertex2f(-1,0);     glEnd();          /*Draw Circle*/          glColor3f(0.0,0.0,1.0);     glBegin(GL_LINES);     glLineWidth(3);          for(i=0;i<=500;i++) //no of short lines to be drawn     {         x = radius + (i-1)*0.002;         y= calculate(x);         /*scale*/         x= x * 2 - 1;         y= y * 2 -1;         glVertex2f(x,y);         x = radius + i*0.002;         y= calculate(x);         x= x * 2 - 1;         y= y * 2 -1;         glVertex2f(x,y);     }     glEnd();     glFlush(); } float calculate(float x) {     return radius - x; //pow(x,2) + pow(y,2) = pow(r,2)                         //y = r - x }  ```
I feel the codes a little weird at the circle area. the axes are all right.
• 10-17-2004
Perspective
if you want to do it without floating point calculations look into Bressenhams Circle Drawing Algorithm
• 10-17-2004
bithub
Code:

```        float x,y;         float radius = 0.5f;         glBegin(GL_LINES);                 glColor3f(0.0f,0.0f,0.0f);                                 x = (float)radius * cos(359 * PI/180.0f);                 y = (float)radius * sin(359 * PI/180.0f);                 for(int j = 0; j < 360; j++)                 {                         glVertex2f(x,y);                         x = (float)radius * cos(j * PI/180.0f);                         y = (float)radius * sin(j * PI/180.0f);                         glVertex2f(x,y);                 }         glEnd();```
• 10-18-2004
bennyho03
thanx for the help but there is a another question though. Why is there a 'f' at the end of
Quote: