【问题标题】:OpenGL FrameBuffer off-screen, on-screen rendering problem with PyQT5PyQT5的OpenGL FrameBuffer离屏、在屏渲染问题
【发布时间】: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


    【解决方案1】:
    glBindFramebuffer(GL_FRAMEBUFFER, 0) #<--- The problem is here. i don't know why
    

    来自documentation for QOpenGLWidget(强调我的):

    所有渲染都发生在一个 OpenGL 帧缓冲区对象中。 makeCurrent() 确保它在上下文中绑定。记住这一点时 在渲染中创建和绑定额外的帧缓冲对象 代码在paintGL()永远不要重新绑定 ID 为 0 的帧缓冲区。相反, 调用defaultFramebufferObject()获取应该绑定的ID。

    【讨论】:

      猜你喜欢
      • 2015-04-08
      • 2018-06-11
      • 2011-04-20
      • 2010-09-17
      • 2014-07-28
      • 1970-01-01
      • 2014-01-12
      • 1970-01-01
      相关资源
      最近更新 更多