Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved QOpenGLWidget::grabFrameBuffer doesn't work with mutli-sampling

    General and Desktop
    2
    3
    863
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • belgiansteve
      belgiansteve last edited by belgiansteve

      Hi,

      Unless I'm doing something wrong, the QOpenGLWidget::grabFrameBuffer doesn't work when multi-sampling is used. This example produces the issue. The image that is saved should be all red, but it's not.

      #include <QApplication>
      #include <QOpenglWidget>
      
      class MyOpenGLWidget : public QOpenGLWidget
      {
      public:
      	MyOpenGLWidget()
      	{
      		QSurfaceFormat f = format();
      		f.setSamples(4);
      		setFormat(f);
      	}
      
      	void initializeGL()
      	{
      		glClearColor(1.f, 0.f, 0.f, 1.f);
      	}
      
      	void resizeGL(int w, int h)
      	{
      		glViewport(0, 0, w, h);
      	}
      
      	void paintGL()
      	{
      		glClear(GL_COLOR_BUFFER_BIT);
      	}
      
      	void mouseReleaseEvent(QMouseEvent* ev)
      	{
      		QImage im = grabFramebuffer();
      		im.save("test.bmp", "BMP");
      	}
      };
      
      int main(int argc, char **argv)
      {
          QApplication app(argc, argv);
      
      	MyOpenGLWidget wnd;
      	wnd.resize(400, 300);
      	wnd.show();
      
          return app.exec();
      }
      
      

      If I don't call setSamples(4) it works fine. Any ideas on what might be going on here?

      Thanks,

      Steve

      1 Reply Last reply Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by

        As stated in the docs this operation uses glReadPixels. It does not support reading from a multisample FBO.
        You must first blit it to another, non-multisample FBO and read from there. See glBlitFramebuffer.

        1 Reply Last reply Reply Quote 1
        • belgiansteve
          belgiansteve last edited by

          Ok, thanks for the reply!

          Steve

          1 Reply Last reply Reply Quote 0
          • First post
            Last post