Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QPainter and QGLFrameBufferObject: black result



  • Goal: I want to render my QGraphicsView onto a QGLFramebufferObject and use the resulting OpenGL texture to overlay my 3D scene. The latter using native OpenGL calls.

    For testing purposes I convert the framebuffer into a QImage, instead of overlaying.

    Issue: When I execute the code below, the result is a full black image. What am I doing wrong?
    [code]
    widget_->makeCurrent();
    QPainter painter(framebuffer_);
    graphicsView_->render(&painter);
    painter.end()
    QImage image = framebuffer_->toImage();
    image.save("test.bmp", "BMP");
    widget_->doneCurrent();
    [/code]

    In which framebuffer_ is set up as follows:
    [code]
    framebuffer_ = new QGLFramebufferObject(800, 600, QGLFramebufferObject::CombinedDepthStencil);
    [/code]

    Rendering directly to a QImage gives me the correct image:
    [code]
    widget_->makeCurrent();
    QImage image(800, 600, QImage::Format_RGB32);
    QPainter painter(&image);
    graphicsView_->render(&painter);
    image.save("test.bmp", "BMP");
    widget_->doneCurrent();
    [/code]

    Context: The code is executed in a separate class that stores the relevant context information, such as the QGLWidget, QGraphicsView and the QGLFramebufferObject. As the 3D scene is drawn before the above code snippets get executed, OpenGL state changes will have occurred, currently being glEnable(GL_DEPTH_TEST) and some shader binds.



  • Peter did you ever figure this out? I'm having a similar issue using QPainter with a QGLFramebufferObject

    http://stackoverflow.com/questions/20819375/qpaint-onto-qglframebufferobject-texture



  • No I haven't. I've avoided this entirely by going with the QtQuick system. This is rather a design change than a solution though.


Log in to reply