我正在尝试使用glReadPixels
. 它工作了一段时间。但是现在它停止工作了,我不知道为什么。
我需要做Flood fill
算法。
glBegin(GL_POINTS);
float target[3] = { 1.0, 1.0, 0.0 }; // target color
float border[3] = { 1.0, 1.0, 1.0 }; // border color
float clearp[3] = { 0.0, 0.0, 0.0 }; // clear color
std::stack<pixel*> colored; // stack with pixels
if (!stack.empty()) // stack contains first pixel
colored.push(stack.top());
while(!colored.empty()) {
pixel *p = colored.top();
glRasterPos2i(p->x, p->y);
glDrawPixels(1, 1, GL_RGB, GL_FLOAT, target);
colored.pop();
//up
float pix[3];
glReadPixels(p->x, p->y + 1, 1, 1, GL_RGB, GL_FLOAT, pix);
if (!compare(pix,border) && compare(pix,clearp)) {
pixel *pn = new pixel();
pn->x = p->x;
pn->y = p->y + 1;
colored.push(pn);
}
//down
glReadPixels(p->x, p->y - 1, 1, 1, GL_RGB, GL_FLOAT, pix);
if (!compare(pix,border) && compare(pix,clearp)) {
pixel *pn = new pixel();
pn->x = p->x;
pn->y = p->y - 1;
colored.push(pn);
}
//left
glReadPixels(p->x - 1, p->y, 1, 1, GL_RGB, GL_FLOAT, pix);
if (!compare(pix,border) && compare(pix,clearp)) {
pixel *pn = new pixel();
pn->x = p->x - 1;
pn->y = p->y;
colored.push(pn);
}
//right
glReadPixels(p->x + 1, p->y, 1, 1, GL_RGB, GL_FLOAT, pix);
if (!compare(pix,border) && compare(pix,clearp)) {
pixel *pn = new pixel();
pn->x = p->x + 1;
pn->y = p->y;
colored.push(pn);
}
}
glEnd();
但数组pix
不包含 RGB 颜色数据。它通常是这样的-1.0737418e+008
问题出在哪里?它应该工作正常...