colour fill help

Started by
3 comments, last by asdfwe 16 years, 1 month ago
in opengl, given a circle at center(x,y) and radius r, how to fill it with a specified colour thanks
Advertisement
Approximate the circle as a fan of triangles (OpenGL cannot render circles natively) and render those triangles with the specified vertex color.
can u please tell the modification required in this code to fill colour in the circle made................

glBegin(GL_LINES);
for ( float angle =0; angle <=2*3.142; angle+=3.142/30)
{

float x1=(radius * cos (angle) / 2) ;
float y1=(radius * sin (angle) / 2) ;
float x2=(radius * cos (angle + 3.142/30) / 2 ;
float y2=(radius * sin (angle + 3.142/30)/ 2) ;
glVertex2f(x1,y1);
glVertex2f(x2,y2);
}
glEnd();
Changing your code as little as possible, I get this:
glBegin(GL_TRIANGLE_FAN);glVertex2f(0,0);for ( float angle =0; angle <=2*3.142; angle+=3.142/30){	float x1=(radius * cos (angle) / 2) ;	float y1=(radius * sin (angle) / 2) ;	glVertex2f(x1,y1);}glVertex2f(radius * cos (angle) / 2, radius * sin (angle) / 2);glEnd();
thanks , it worked

This topic is closed to new replies.

Advertisement