From 7e4969f3298daab33429fe32ae0079f0fbbde3b0 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Tue, 14 Jan 2020 02:21:15 +0000 Subject: [PATCH] Gui: fix screentshot --- src/Gui/SoFCOffscreenRenderer.cpp | 6 ++---- src/Gui/View3DInventorViewer.cpp | 27 +++++++++++++++++++++++++-- src/Mod/Part/Gui/SoBrepFaceSet.cpp | 9 --------- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/Gui/SoFCOffscreenRenderer.cpp b/src/Gui/SoFCOffscreenRenderer.cpp index 4b6524124a..c09b16c019 100644 --- a/src/Gui/SoFCOffscreenRenderer.cpp +++ b/src/Gui/SoFCOffscreenRenderer.cpp @@ -31,6 +31,7 @@ # include # include # include +# include #endif #if !defined(FC_OS_MACOSX) @@ -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; @@ -818,9 +819,6 @@ SoQtOffscreenRenderer::writeToImage (QImage& img) const } } } - else if (PRIVATE(this)->backgroundcolor[3] == 1.0) { - img = img.convertToFormat(QImage::Format_RGB32); - } } /*! diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index ed57bfc920..eda68903ff 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -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)) @@ -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(); @@ -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 @@ -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) diff --git a/src/Mod/Part/Gui/SoBrepFaceSet.cpp b/src/Mod/Part/Gui/SoBrepFaceSet.cpp index 466094379b..441a9c695a 100644 --- a/src/Mod/Part/Gui/SoBrepFaceSet.cpp +++ b/src/Mod/Part/Gui/SoBrepFaceSet.cpp @@ -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.