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() always ignores alpha channel?

QOpenGLWidget::grabFrameBuffer() always ignores alpha channel?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qopenglwidgetalphatransparencyqglwidgetgrabframebuffer
3 Posts 2 Posters 1.2k 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.
  • T Offline
    T Offline
    thehans
    wrote on last edited by
    #1

    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
    0
    • T Offline
      T Offline
      thehans
      wrote on last edited by
      #2

      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?

      JKSHJ 1 Reply Last reply
      0
      • T thehans

        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?

        JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        @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
        2

        • Login

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