由于glReadPixels返回奇数(我全为0或全部为-1.07374e + 08,这取决于浮点pixel [3]是全局变量还是局部变量),因此我无法泛洪填充刚刚创建的椭圆。
我尝试更改pixel [3]的位置,以及将泛洪填充算法更改为递归工作而不是不排队,但这两种方法均无效。
`
void FFill(int xin, int yin, float colorin[3]) {
float pixel[3], clearc[3];
glReadPixels(xin, yin, 1.0, 1.0, GL_RGB, GL_FLOAT, clearc);
glVertex2i(xin, yin);
std::queue<vector<int>> q;
vector<int> n = { xin, yin };
q.push(n);
while (!q.empty())
{
n = q.front();
q.pop();
n[0] -= 1;
glReadPixels(n[0], n[1], 1.0, 1.0, GL_RGB, GL_FLOAT, pixel);
if (pixel[0] == clearc[0] && pixel[1] == clearc[1] && pixel[2] == clearc[2])
{
glVertex2i(n[0], n[1]);
q.push(n);
}
n[0] += 2;
glReadPixels(n[0], n[1], 1.0, 1.0, GL_RGB, GL_FLOAT, pixel);
if (pixel[0] == clearc[0] && pixel[1] == clearc[1] && pixel[2] == clearc[2])
{
glVertex2i(n[0], n[1]);
q.push(n);
}
n[1] -= 1;
glReadPixels(n[0], n[1], 1.0, 1.0, GL_RGB, GL_FLOAT, pixel);
if (pixel[0] == clearc[0] && pixel[1] == clearc[1] && pixel[2] == clearc[2])
{
glVertex2i(n[0], n[1]);
q.push(n);
}
n[1] += 2;
glReadPixels(n[0], n[1], 1.0, 1.0, GL_RGB, GL_FLOAT, pixel);
if (pixel[0] == clearc[0] && pixel[1] == clearc[1] && pixel[2] == clearc[2])
{
glVertex2i(n[0], n[1]);
q.push(n);
}
n.clear();
}
}
`
所以,当我运行这段代码时,我希望它能填满椭圆,但是,它将一直填充队列直到崩溃。