Public Group

# colour fill help

This topic is 3802 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

in opengl, given a circle at center(x,y) and radius r, how to fill it with a specified colour thanks

##### Share on other sites
Approximate the circle as a fan of triangles (OpenGL cannot render circles natively) and render those triangles with the specified vertex color.

##### Share on other sites
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();

##### Share on other sites
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();

##### Share on other sites
thanks , it worked

1. 1
Rutin
26
2. 2
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 21
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631763
• Total Posts
3002189
×