Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QOpenGLWidget::grabFrameBuffer doesn't work with mutli-sampling
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.1k Views
  • 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.
  • belgiansteveB Offline
    belgiansteveB Offline
    belgiansteve
    wrote on last edited by belgiansteve
    #1

    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
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      1
      • belgiansteveB Offline
        belgiansteveB Offline
        belgiansteve
        wrote on last edited by
        #3

        Ok, thanks for the reply!

        Steve

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved