• Advertisement
Sign in to follow this  

colour fill help

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement