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

Artifacts when rendring QOpenGLWidget to QImage

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 384 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.
  • gde23G Offline
    gde23G Offline
    gde23
    wrote on 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
    • nageshN Offline
      nageshN Offline
      nagesh
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • gde23G Offline
        gde23G Offline
        gde23
        wrote on 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
        • nageshN Offline
          nageshN Offline
          nagesh
          wrote on 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

          • Login

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