• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# algortims for making circles in opengl

## 4 posts in this topic

is there a way to make a circle out of triangles in opengl. i figure if the vertices are close enough it could look like a circle. any help would be appreciated
0

##### Share on other sites
use GL_TRIANGLE FAN. start with a center point, and then plot however many points you want in r*cos(angle) and r*sin(angle) fashion, where those two cos/sin statements are the x,y coords, and r is the radius.
0

##### Share on other sites
Im not sure exactly what you mean by that, could you maybe show the a sample of actual code that would do all that you said. thanks

0

##### Share on other sites
sure.
(this is pseudocode, cuz i'm not sure if it'll compile, but i'll try to make it almost code.)

#define DTR //degrees to radians (2pi/360)

GLfloat center[2] = {30,30};

glBegin(GL_TRIANGLE_FAN);
glVertex2d(center[0], center[1]);
for (int angle = 0; angle <=360; angle ++)
{
glVertex2d(center[0] + (radius * cos(angle * DTR)),
center[1] + (radius * sin(angle * DTR));
}

glEnd();

// this code should render a circle with a refinement of
// every degree out of 360. i don't think you necessarily
// need a refinement of 360 degrees, but if not, just
//change the increment value of angle by a factor of 360.

a2k

Edited by - a2k on 4/19/00 8:06:26 PM

Edited by - a2k on 4/19/00 8:12:08 PM

Edited by - a2k on 4/19/00 8:13:38 PM
0

##### Share on other sites
Well, there is that gelDrawPerfectAss() function in OpenGEL...
0