colour fill help
in opengl, given a circle at center(x,y) and radius r, how to fill it with a specified colour
thanks
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();
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();
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement