PDA

View Full Version : Recursive filling doesn't work



soleil_froid
03-25-2016, 09:20 PM
Hi! I'm trying to write recursive function, which fill a closed field pixel by pixel. I'm using glReadPixels for finding color of current pixel. But when my function runs to the border of field, glReadPixels doesn't read border color, it reads only backgroung color, so I have infinite recursion. What can I do?
Here is part of my code:


void dot(GLint x, GLint y) {
glPointSize(1);
glBegin(GL_POINTS);
glVertex2i(x, y);
glEnd();
glFlush();
}

void fill (GLint a, GLint b) {//a and b-points in field
GLubyte data[3], border[] = {0, 0, 0};//color of border
glReadBuffer(GL_FRONT);
glReadPixels(a, b, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &data[0]);
int i;
for ( i = 0; i < 3 && data[i] == border[i]; i++ );
if ( i < 3 ) { //pixel color doesn't equal to the border color
dot(a, b);
fill(a, b + 1 ); fill(a + 1, b ); fill(a, b - 1 ); fill(a - 1, b );
}
}