Advertisement

algortims for making circles in opengl

Started by April 19, 2000 08:29 AM
3 comments, last by madmax22e 24 years, 7 months ago
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
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.
------------------General Equation, this is Private Function reporting for duty, sir!a2k
Advertisement
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

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};
GLfloat radius = 10.0;

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
------------------General Equation, this is Private Function reporting for duty, sir!a2k
Well, there is that gelDrawPerfectAss() function in OpenGEL...

This topic is closed to new replies.

Advertisement