OpenGL背景透明度?
我正在使用 QT 的 QGLFramebufferObject 进行离屏渲染。
渲染到缓冲区后,我使用 glReadPixels() 读取结果
问题是有时我读取的背景颜色只是0(透明黑色)有时是0xFF000000(不透明黑色)
这似乎与缓冲区初始化的时间有关。 如果缓冲区是从 QGLWidget 继承的类的成员,则它是 0。如果它在其他任何地方初始化,则它是 0xFF000000。
有人知道这里发生了什么事吗? 这次阅读的良好预期结果是什么?
I'm using QT's QGLFramebufferObject for off-screen rendering.
After rendering to the buffer I read the result using glReadPixels()
The problem is that sometimes the background color I read is just 0 (transparent black) and sometimes it is 0xFF000000 (opaque black)
This seem to be related to the time the buffer is initialized. If the buffer is a member of the class inherited from QGLWidget then it is 0. If it is initialized anywhere else it's 0xFF000000.
Does anybody have any idea what's going on here? What is the good expected result of this read?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否设置了正确的透明颜色 (glClearColor) 并实际执行了透明 (glClear)? 您是否确保颜色写入(glColorMask)掩码已完全启用(它也会影响清除)。 接下来,您可以检查 QT 是否设置了一些奇怪的像素复制传输(默认值除外,请参见 glPixelStore、glPixelTransfer 和 glPixelMap)。 您确定在这两种情况下都获取(并读入)RGBA 缓冲区,而不仅仅是 RGB 吗? 最后,帧缓冲区对象扩展很可能在您的特定显卡/驱动程序组合上存在错误,如果没有主要可见窗口,则更是如此。 至少检查两家供应商的卡。 当然,在所有可能失败的操作之后始终检查 glGetError。
重新阅读您的问题后,您在非 QGLWidget 情况下是否得到任何其他有效的渲染? 明确说绿,还绿吗? 因为在这种情况下,很可能您只是没有初始化任何有效的 OpenGL 上下文。 与 pbuffer 不同,帧缓冲区对象需要外部上下文。
Do you set up the correct clear color (glClearColor) and actually do a clear (glClear)? Are you making sure that your color write (glColorMask) mask is fully enabled (it also affects clears). Next you can check if QT sets up some weird pixel copy transfer (other than the default, see glPixelStore, glPixelTransfer and glPixelMap). Are you sure you are getting (and reading into) an RGBA buffer in both cases, not just RGB? Lastly, it is very well possible that the framebuffer object extension is buggy on your particular graphics card/driver combination, more so if there is no primary visible window. At least check cards from both vendors. And of course always check glGetError after all potentially failing operations.
After re-reading your question, do you get any other valid rendering in the non QGLWidget case at all? Does clear to say green, return green? Because it might very well be that you just did not initialize any valid OpenGL context to begin with in that case. Framebuffer objects, unlike pbuffers need an external context.
谜团已解
看来我给GLWidget的透明颜色是0,默认的透明颜色是0xff000000。 根据我初始化帧缓冲区对象的时间,它接收 GLWidget 的当前清晰颜色。
Mystery solved
It seems that the clear color I give to the GLWidget is 0 and the default clear color is 0xff000000. Depending on when I initialize the framebuffer object, it receives the GLWidget's current clear color.