glReadPixels 和 Alpha 通道返回 1.0
我正在从帧缓冲区读取像素数据,除了 alpha 值始终为 1.0 之外,一切似乎都正常工作
GLfloat lebuf[areasize * 4];
glReadPixels(xstart, ystart, partw, parth, GL_RGBA, GL_FLOAT, lebuf);
我已将窗口创建代码设置为支持 alpha 通道:
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8);
是否还有其他我应该查找的地方检查为什么 alpha 通道似乎一直是 1.0?更好的是,是否有另一种方法(除了 glReadPixels 之外)将纹理从帧缓冲区获取到客户端内存?
编辑:这就是我清除缓冲区的方法:
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
I'm reading pixel data from a framebuffer, and everything seems to work, except for the alpha value, which is always 1.0
GLfloat lebuf[areasize * 4];
glReadPixels(xstart, ystart, partw, parth, GL_RGBA, GL_FLOAT, lebuf);
I've set the window creation code to support an alpha channel:
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8);
Is there any other place I should look at for checking why the alpha channel seems to be 1.0 all the time? Better yet, is there another way (other than glReadPixels) to get the texture into client memory, from the framebuffer?
edit: this is how I clear the buffer:
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您能否检查一下:
glGetIntegerv(GL_ALPHA_BITS, bits)
)?glClearColor
)。如果您清除为 0.5 并在渲染之前检索缓冲区会怎样?你检索0.5吗?glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE)
)?Could you check:
glGetIntegerv(GL_ALPHA_BITS, bits)
)?glClearColor
). What if you clear to 0.5 and retrieve the buffer before rendering. Do you retrieve 0.5?glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE)
)?如果您使用 GLUT,请记住您必须按如下方式设置主窗口:
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA | GLUT_DEPTH | GLUT_STENCIL);
否则 glReadPixels 将始终读取 alpha 通道 = 1。
If you are using GLUT, remember you have to set your main window as follows:
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA | GLUT_DEPTH | GLUT_STENCIL);
otherwise glReadPixels will read always alpha channel = 1.
请使用以下行..问题将得到解决。
Please use the following line.. problem will solved.