i want to implement the flood fill algorthm...so that when i get the x and y co-od of a point...it should start flooding from that point and fill till it finds a boundary but it is not filling the entire region...say a pentagon
this is the code i am using
void setpixel(struct fill fillcolor,int x,int y)
{
glColor3f(fillcolor.r,fillcolor.g,fillcolor.b);
glBegin(GL_POINTS);
glVertex2i(x,y);
glEnd();
glFlush();
}
struct fill getpixcol(int x,int y)
{
struct fill gotpixel;
glReadPixels(x,y,1,1,GL_RGB,GL_UNSIGNED_BYTE,pick_col);
gotpixel.r =(float) pick_col[0]/255.0;
gotpixel.g =(float) pick_col[1]/255.0;
gotpixel.b =(float) pick_col[2]/255.0;
return(gotpixel);
}
void floodFill(int x, int y,struct fill fillcolor,struct fill boundarycolor)
{
struct fill tmp;
// if ((x < 0) || (x >= 500)) return;
// if ((y < 0) || (y >= 500)) return;
tmp=getpixcol(x,y);
while (tmp.r!=boundarycolor.r && tmp.g!=boundarycolor.g && tmp.b!=boundarycolor.b)
{
setpixel(fillcolor,x,y);
setpixel(fillcolor,x+1,y);
setpixel(fillcolor,x,y+1);
setpixel(fillcolor,x,y-1);
setpixel(fillcolor,x-1,y);
floodFill(x-1,y+1,fillcolor,boundarycolor);
floodFill(x-1,y,fillcolor,boundarycolor);
floodFill(x-1,y-1,fillcolor,boundarycolor);
floodFill(x,y+1,fillcolor,boundarycolor);
floodFill(x,y-1,fillcolor,boundarycolor);
floodFill(x+1,y+1,fillcolor,boundarycolor);
floodFill(x+1,y,fillcolor,boundarycolor);
floodFill(x+1,y-1,fillcolor,boundarycolor);
}
}