【发布时间】:2020-11-14 03:23:43
【问题描述】:
我正在尝试渲染到 fbo 以使用 glReadPixels。我可以渲染到 fbo 并读取像素值,但我无法在屏幕上渲染它,我收到如下错误:
错误 = 1286, description = b'无效的帧缓冲操作',
这是我的步骤:
class MyGLWidget(QOpenGLWidget):
...
...
def paintGl():
### offscreen rendering ###
glBindFramebuffer(GL_FRAMEBUFFER, self.fbo);
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
# ... bind texture ...
# ... shader program...
# ... VAO
# ... EBO
# ... uniforms
# ... draw
glBindFramebuffer(GL_FRAMEBUFFER, 0) #<--- The problem is here. i don't know why
### read pixel ###
glBindFramebuffer(GL_READ_FRAMEBUFFER, self.fbo)
glReadBuffer(GL_COLOR_ATTACHMENT0)
print(glReadPixels(0, 0, _width, _height, _format, _type)) #<-- I got correct value here.
### on screen render ###
glClearColor(0.0, 0.0, 0.0, 1.0) #<---I got an error here
glClear(GL_COLOR_BUFFER_BIT)
# ... bind texture (color attachment texture)
# ... shader program...
# ... VAO
# ... EBO
glDrawElements(mode, count, _type, indices) #<--- If i don't use glClear, I get an error here.
问题出在glBindFramebuffer(GL_FRAMEBUFFER, 0)这一行
如果我删除该行,我不会收到错误消息,但会出现黑屏。
我不知道我做错了什么,或者可能是我的显卡中的错误或 QOpenGLWidget 中的错误。
希望你能帮忙。
提前致谢。
【问题讨论】:
标签: python opengl pyqt5 framebuffer pyopengl