Skip to content

Commit

Permalink
Gui: fix screentshot
Browse files Browse the repository at this point in the history
  • Loading branch information
realthunder authored and wwmayer committed Jan 14, 2020
1 parent 1f05c8f commit 5afd6a9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
6 changes: 2 additions & 4 deletions src/Gui/SoFCOffscreenRenderer.cpp
Expand Up @@ -31,6 +31,7 @@
# include <QFile>
# include <QImage>
# include <QImageWriter>
# include <QPainter>
#endif

#if !defined(FC_OS_MACOSX)
Expand Down Expand Up @@ -405,7 +406,7 @@ void SoQtOffscreenRenderer::init(const SbViewportRegion & vpr,
else {
this->renderaction = new SoGLRenderAction(vpr);
this->renderaction->setCacheContext(SoGLCacheContextElement::getUniqueCacheContext());
this->renderaction->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_BLEND);
this->renderaction->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND);
}

this->didallocation = glrenderaction ? false : true;
Expand Down Expand Up @@ -818,9 +819,6 @@ SoQtOffscreenRenderer::writeToImage (QImage& img) const
}
}
}
else if (PRIVATE(this)->backgroundcolor[3] == 1.0) {
img = img.convertToFormat(QImage::Format_RGB32);
}
}

/*!
Expand Down
27 changes: 25 additions & 2 deletions src/Gui/View3DInventorViewer.cpp
Expand Up @@ -1608,6 +1608,7 @@ void View3DInventorViewer::savePicture(int w, int h, int s, const QColor& bg, QI
renderer.setViewportRegion(vp);
renderer.getGLRenderAction()->setSmoothing(true);
renderer.getGLRenderAction()->setNumPasses(s);
renderer.getGLRenderAction()->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND);
if (bgColor.isValid())
renderer.setBackgroundColor(SbColor(bgColor.redF(), bgColor.greenF(), bgColor.blueF()));
if (!renderer.render(root))
Expand All @@ -1616,6 +1617,15 @@ void View3DInventorViewer::savePicture(int w, int h, int s, const QColor& bg, QI
renderer.writeToImage(img);
root->unref();
}

if (!bgColor.isValid() || bgColor.alphaF() == 1.0) {
QImage image(img.width(), img.height(), QImage::Format_RGB32);
QPainter painter(&image);
painter.fillRect(image.rect(), Qt::black);
painter.drawImage(0, 0, img);
painter.end();
img = image;
}
}
catch (...) {
root->unref();
Expand Down Expand Up @@ -2048,6 +2058,13 @@ QImage View3DInventorViewer::grabFramebuffer()
renderToFramebuffer(&fbo);

res = fbo.toImage(false);

QImage image(res.width(), res.height(), QImage::Format_RGB32);
QPainter painter(&image);
painter.fillRect(image.rect(),Qt::black);
painter.drawImage(0, 0, res);
painter.end();
res = image;
}
#endif

Expand Down Expand Up @@ -2111,8 +2128,14 @@ void View3DInventorViewer::imageFromFramebuffer(int width, int height, int sampl
bits++;
}
}
} else if (alpha == 255)
img = img.convertToFormat(QImage::Format_RGB32);
} else if (alpha == 255) {
QImage image(img.width(), img.height(), QImage::Format_RGB32);
QPainter painter(&image);
painter.fillRect(image.rect(),Qt::black);
painter.drawImage(0, 0, img);
painter.end();
img = image;
}
}

void View3DInventorViewer::renderToFramebuffer(QtGLFramebufferObject* fbo)
Expand Down
9 changes: 0 additions & 9 deletions src/Mod/Part/Gui/SoBrepFaceSet.cpp
Expand Up @@ -617,15 +617,6 @@ void SoBrepFaceSet::GLRender(SoGLRenderAction *action)
// material override with transparncy won't work.
mb.sendFirst();

if(SoShapeStyleElement::get(state)->getFlags()
& (SoShapeStyleElement::TRANSP_TEXTURE|SoShapeStyleElement::TRANSP_MATERIAL))
{
// For some reason, there is an inconsistence in blending state between
// OpenGL and Coin, especially when doing offscreen rendering.
if(!glIsEnabled(GL_BLEND))
glEnable(GL_BLEND);
}

// When setting transparency shouldGLRender() handles the rendering and returns false.
// Therefore generatePrimitives() needs to be re-implemented to handle the materials
// correctly.
Expand Down

0 comments on commit 5afd6a9

Please sign in to comment.