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



  • 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


  • Moderators

    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.



  • Ok, thanks for the reply!

    Steve


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.