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. Artifacts when rendring QOpenGLWidget to QImage
Forum Updated to NodeBB v4.3 + New Features

Artifacts when rendring QOpenGLWidget to QImage

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 395 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.
  • G Offline
    G Offline
    gde23
    wrote on 23 Apr 2021, 12:16 last edited by
    #1

    Hello,

    I have a QOpenGLWidget that I want to render to an png image.

    This is my code (in a method of class derived from QOpenGLWIdget):

    QSize size = QSize(scale*this->width(), scale*this->height());
    QImage img = QImage(size, QImage::Format_RGB32);
    QPainter painter(&img);
    painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    this->render(&painter);
    img.save(filename);
    

    Now the thing that I want to render e.g. looks like this.
    As the screenshot taken from the GUI shows it looks like it should.
    ogl_good.jpeg

    However when I want to save the exact same thing (using the code above) I get following:
    ogl_bad.png
    So it seems that the regions where there is lots of specular reflections first get yellow, and if its even more then black.

    Why is that?

    1 Reply Last reply
    0
    • N Offline
      N Offline
      nagesh
      wrote on 25 Apr 2021, 10:00 last edited by
      #2

      @gde23 Where is the drawing code? What is rendered to img through QPainter?

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gde23
        wrote on 27 Apr 2021, 15:43 last edited by
        #3

        @nagesh : thanks for the answer however I dont thinkt it has to do we the opengl drawing code. Nothing special is happening there, just some triangles.

        I found a solution/workaround myself:
        Instead of rendering via QPainter there is a method in QOpenGLWidget that I didn't know existed:

        QOpenGLWIdget::grabFramebuffer()
        

        This woks for me and I can obtain the image without the artifacts. I still don't understand what went wrong in the first place, but anyway, that's fine.

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nagesh
          wrote on 28 Apr 2021, 01:13 last edited by
          #4

          @gde23 good that you got the solution

          Problem in earlier code might be because of
          1)img is unintialized // fill with transparency
          2)in order to take the screen shot , you are doing again drawing in img. rather than direct screen grab of window

          1 Reply Last reply
          0

          1/4

          23 Apr 2021, 12:16

          • Login

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