glReadPixels获得的像素值alpha始终是255

glReadPixels(0,0, 1, 1, GL_ALPHA, GL_UNSIGNED_BYTE, data);
data中的值始终是255
搜了下,都说要开启opengl像素格式
typedef struct tagPIXELFORMATDESCRIPTOR
{ // pfd
WORD nSize; //结构大小: sizeof(PIXELFORMATDISCRIPTOR)
WORD nVersion; //版本: 1
DWORD dwFlags; //像素缓冲区属性
BYTE iPixelType; //像素格式
BYTE cColorBits; //颜色缓冲区中位平面的数量
BYTE cRedBits; //用多少位表示红色
BYTE cRedShift; //红色位的移位计数
BYTE cGreenBits;
BYTE cGreenShift;
BYTE cBlueBits;
BYTE cBlueShift;
BYTE cAlphaBits;
BYTE cAlphaShift;
BYTE cAccumBits; //积累缓冲区位数
BYTE cAccumRedBits; //积累缓冲区中红色的位数
BYTE cAccumGreenBits;
BYTE cAccumBlueBits;
BYTE cAccumAlphaBits;
BYTE cDepthBits; //深度缓冲区位数
BYTE cStencilBits; //模板缓冲区位数
BYTE cAuxBuffers; //多少个辅助缓冲区
BYTE iLayerType; //过时或忽略
BYTE bReserved; //上层或下层平面的数量
DWORD dwLayerMask; //过时或忽略
DWORD dwVisibleMask; //下平面的透明颜色
DWORD dwDamageMask; //过时或忽略
} PIXELFORMATDESCRIPTOR;

需要设置cAlphaBits
但我并没有在cocos2d-x中的GLView中找到设置这些东西的地方
求指导

请问 这个问题楼主解决了么?开启opengl像素格式。。。

贡献一个我写的像素检测:
里面有如何拿像素点的代码。

bool Sprite::hitTestInPixel(int x, int y ){

const Size  spSize = this->getContentSize();

// CCLOG(“当前点击范围: size= {%f,%f},pos:{%d,%d}”, spSize.width,spSize.height ,x,y);
RenderTexture * renderTexture=RenderTexture::create(
spSize.width,
spSize.height,
Texture2D::PixelFormat::RGBA8888,
GL_DEPTH24_STENCIL8_OES
);
renderTexture->ignoreAnchorPointForPosition(true);
renderTexture->setAnchorPoint(Size(0, 0));
//绘制使用的临时精灵,与原图是同一图片
Sprite* pTempSpr = Sprite::createWithSpriteFrame(this->displayFrame());
//pTempSpr->setPosition( pTempSpr->getContentSize().width / 2, pTempSpr->getContentSize().height / 2) ;
pTempSpr->setAnchorPoint(Size(0, 0));

renderTexture->beginWithClear(0,0,0,0);
pTempSpr->visit();
renderTexture->end();

Director::getInstance()->getRenderer()->render();

Image *img=renderTexture->newImage();
unsigned char *imgdata=img->getData();
unsigned int *pixel = (unsigned int *)imgdata;
unsigned int *tempPixel = pixel + ((int(spSize.height)-y) * (int)spSize.width) * 1 + x * 1;

// Color4B color4B = {0, 0, 0, 0};
// //R通道
// color4B.r = *tempPixel & 0xff;
// //G通道
// color4B.g = (*tempPixel >> 8) & 0xff;
// //B通过
// color4B.b = (*tempPixel >> 16) & 0xff;
// //Alpha通道,我们有用的就是Alpha
// color4B.a = (*tempPixel >> 24) & 0xff;

//CCLOG("当前点击的点的: color = {%d,%d,%d,%d}", color4B.r ,color4B.g,color4B.b,color4B.a );

uint alpha=(*tempPixel >> 24) & 0xff;


bool isTouched=true;

if (alpha > 25) {
isTouched = true;
} else {
isTouched = false;
}

//绘制完成后清理画布的内容
renderTexture->clear(0, 0, 0, 0);
//renderTexture->release();
img->release();
 return isTouched;

}

用autopolygon 做