Artifacts when rendring QOpenGLWidget to QImage
-
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.
However when I want to save the exact same thing (using the code above) I get following:
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?
-
@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.