glReadPixels 和 Alpha 通道返回 1.0

发布于 2024-10-12 07:03:55 字数 529 浏览 2 评论 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

伴我心暖 2024-10-19 07:03:55

您能否检查一下:

  • 您的 SDL 是否已接受您的格式 (glGetIntegerv(GL_ALPHA_BITS, bits))?
  • 您的颜色清除不是 1 (glClearColor)。如果您清除为 0.5 并在渲染之前检索缓冲区会怎样?你检索0.5吗?
  • 你的alpha缓冲区没有写锁定(glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE))?
  • 您是否在每帧末尾正确清除了 alpha 缓冲区?
  • 您的混合函数会将正确的 alpha 值写入缓冲区吗?

Could you check:

  • That you SDL has accepted your format (glGetIntegerv(GL_ALPHA_BITS, bits))?
  • That your color clear is not 1 (glClearColor). What if you clear to 0.5 and retrieve the buffer before rendering. Do you retrieve 0.5?
  • That you alpha buffer is not write locked (glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE))?
  • That you correctly clear your alpha buffer at the end of each frame?
  • That your blend function will write the correct alpha value to the buffer?
相思碎 2024-10-19 07:03:55

如果您使用 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.

新雨望断虹 2024-10-19 07:03:55

请使用以下行..问题将得到解决。

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA | GLUT_DEPTH | GLUT_STENCIL);

Please use the following line.. problem will solved.

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA | GLUT_DEPTH | GLUT_STENCIL);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文