[英]glReadPixels doesn't work
我正在尝试使用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
问题出在哪儿? 它应该工作正常...
调用glBegin
和glEnd
之间的函数集非常有限,这是一个错误。 该列表主要由与指定顶点属性相关的函数组成(例如glVertex
, glNormal
, glColor
, glTexCoord
等)。
因此,如果您的OpenGL实现遵循OpenGL规范,则glReadPixels
应该立即返回而不执行,因为在glBegin/glEnd
组中被调用了。 从通话中删除那些电话, glReadPixels
应该可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.