为什么根据网上找的资料,用glReadPixels但不起作用
int8_t data;
Point touchPoint = bgSprite->convertTouchToNodeSpace(touch);
//Point touchPoint = bgSprite->convertToNodeSpace§;
Point location = Point((touchPoint.x) * CC_CONTENT_SCALE_FACTOR(), (touchPoint.y) * CC_CONTENT_SCALE_FACTOR());
RenderTexture* renderTexture = RenderTexture::create(1 * CC_CONTENT_SCALE_FACTOR(),1 * CC_CONTENT_SCALE_FACTOR(), Texture2D::PixelFormat::RGBA8888);
//RenderTexture* renderTexture = RenderTexture::create(640, 1136, Texture2D::PixelFormat::RGBA8888);
renderTexture->beginWithClear(0,0,0,0);//只保存渲染一个像素的数据
//renderTexture->begin();
Point oldPos = bgSprite->getPosition();
Point oldAnchor = bgSprite->getAnchorPoint();
bgSprite->setAnchorPoint(Point(0, 0));
bgSprite->setPosition(Point(-location.x, -location.y));
//renderTexture->begin();
bgSprite->visit();
bgSprite->setAnchorPoint(oldAnchor);
bgSprite->setPosition(oldPos);
glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, data);
renderTexture->end();
//renderTexture->release();
//检测alpha值
log(“X:.0f y:.0f R: %d, G: %d, B: %d, A: %d tag:%d”,location.x ,location.y, data, data, data, data, this->getTag());
if(data || data || data || data)
{
log(“fei tou ming”);
}else{
log(“sssssss”);
}
这是代码,打印出来的RGBA值全为-1
没人回答吗?求指教
偶尔e网事,能帮我看一下吗