Qt Forum

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

    Call for Presentations - Qt World Summit

    Unsolved QOpenGLWidget::grabFrameBuffer() always ignores alpha channel?

    General and Desktop
    qopenglwidget alpha transparency qglwidget grabframebuffer
    2
    3
    512
    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.
    • T
      thehans last edited by

      I have an application using QOpenGLWidget, and I want to be able to export images by grabbing the frame buffer, where the background "clear color" may optionally contain transparencies.
      But, it seems that no matter what I do, the QImage returned by grabFrameBuffer() always returns false for QImage::hasAlpha().

      I am currently setting the default surface format like so:

      auto qsf = QSurfaceFormat::defaultFormat();
      if (!qsf.hasAlpha()) {
      	qsf.setAlphaBufferSize(8);
      	QSurfaceFormat::setDefaultFormat(qsf);
      }
      

      I even do this before instantiating QApplication, based on the Note: section in the documentation here

      Note: Calling QSurfaceFormat::setDefaultFormat() before constructing the QApplication instance is mandatory on some platforms (for example, macOS) when an OpenGL core profile context is requested. This is to ensure that resource sharing between contexts stays functional as all internal contexts are created using the correct version and profile."""
      

      Is there something else I'm missing that's needed to get the alpha from this function, or is it a bug in QOpenGLWidget?

      It seems like the description of QOpenGLWidget::grabFrameBuffer is a lie when it says "Renders and returns a 32-bit RGB image of the framebuffer."
      Since it appears to only return 24 bits and throw away alpha channel.

      I don't understand why the incredibly useful withAlpha argument from deprecated QGLWidget:
      QGLWidget::grabFrameBuffer(bool withAlpha = false)
      was removed in QOpenGLWidget which replaced it?

      1 Reply Last reply Reply Quote 0
      • T
        thehans last edited by

        I had to peek at the source and found that it has been a bug, fixed in this commit: https://codereview.qt-project.org/c/qt/qtbase/+/235928

        As far as I understand this fixed was applied to Qt 5.12 and up.

        Unfortunately I'm on Ubuntu 18.04 which is still on 5.9.5.
        Is there any chance of this fix being backported to earlier versions?

        JKSH 1 Reply Last reply Reply Quote 0
        • JKSH
          JKSH Moderators @thehans last edited by

          @thehans said in QOpenGLWidget::grabFrameBuffer() always ignores alpha channel?:

          Unfortunately I'm on Ubuntu 18.04 which is still on 5.9.5.
          Is there any chance of this fix being backported to earlier versions?

          Qt 5.9 is now in "very strict" update mode, which means in only receives security fixes. It no longer receives bug fixes.

          Your options are:

          • Download and use Qt 5.12 or newer from https://www.qt.io/download-open-source, OR
          • Apply the patch to your copy of Qt 5.9 and build it from source.

          I think the first option is easier.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

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