Commit 78639831 authored by Mike Kremer's avatar Mike Kremer

Added transparency trigger to snapshot function.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9910 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 485237f7
...@@ -1207,7 +1207,7 @@ void Core::snapshotBaseFileName(const QString& _fname, unsigned int _viewerId ){ ...@@ -1207,7 +1207,7 @@ void Core::snapshotBaseFileName(const QString& _fname, unsigned int _viewerId ){
} }
void Core::snapshot( unsigned int _viewerId, int _width, int _height ){ void Core::snapshot( unsigned int _viewerId, int _width, int _height, bool _alpha ){
if ( OpenFlipper::Options::gui() ) { if ( OpenFlipper::Options::gui() ) {
...@@ -1215,7 +1215,7 @@ void Core::snapshot( unsigned int _viewerId, int _width, int _height ){ ...@@ -1215,7 +1215,7 @@ void Core::snapshot( unsigned int _viewerId, int _width, int _height ){
emit log(LOGERR,tr("Unable to create snapshot for viewer ") + QString::number(_viewerId) ); emit log(LOGERR,tr("Unable to create snapshot for viewer ") + QString::number(_viewerId) );
return; return;
} }
coreWidget_->examiner_widgets_[_viewerId]->snapshot(_width, _height); coreWidget_->examiner_widgets_[_viewerId]->snapshot(_width, _height, _alpha);
} }
} }
...@@ -1350,6 +1350,17 @@ void Core::setDescriptions(){ ...@@ -1350,6 +1350,17 @@ void Core::setDescriptions(){
" in snap.png in the current directory. For every snapshot" " in snap.png in the current directory. For every snapshot"
" a counter is added to the filename."), QStringList(QString("viewerId;width;height").split(";")), " a counter is added to the filename."), QStringList(QString("viewerId;width;height").split(";")),
QStringList(QString("Id of viewer (default is 0);Width of image;Height of image").split(";"))); QStringList(QString("Id of viewer (default is 0);Width of image;Height of image").split(";")));
emit setSlotDescription("snapshot(uint,int,int,bool)", tr("Make a snapshot of the viewer with id viewerId."
" Pass 0 as viewerId parameter to capture the current viewer. "
" The captured image will have the specified dimensions. "
" If 0 is passed as either width or height parameter, the value will "
" automatically be set to hold the right aspect ratio, respectively. "
" If 0 is passed for both width and height values, the viewport's current "
" dimension is used. Set alpha to true if you want the background to be transparent. "
" If no filename was set using snapshotBaseFileName() the snapshot is stored"
" in snap.png in the current directory. For every snapshot"
" a counter is added to the filename."), QStringList(QString("viewerId;width;height;alpha").split(";")),
QStringList(QString("Id of viewer (default is 0);Width of image;Height of image;Transparent background").split(";")));
emit setSlotDescription("resizeViewer(int,int)", tr("Resize the viewer"), emit setSlotDescription("resizeViewer(int,int)", tr("Resize the viewer"),
QString(tr("width,height")).split(","), QString(tr("width,height")).split(","),
QString(tr("new width for the viewer,new height for the viewer")).split(",")); QString(tr("new width for the viewer,new height for the viewer")).split(","));
......
...@@ -468,7 +468,7 @@ public slots: ...@@ -468,7 +468,7 @@ public slots:
the current snapshot counter. The \a back buffer will be saved. the current snapshot counter. The \a back buffer will be saved.
The id of the current viewer is 0 (default). The id of the current viewer is 0 (default).
*/ */
void snapshot(unsigned int _viewerId = 0, int _width = 0, int _height = 0); void snapshot(unsigned int _viewerId = 0, int _width = 0, int _height = 0, bool _alpha = false);
/// Take a snapshot from the whole app /// Take a snapshot from the whole app
void applicationSnapshot(); void applicationSnapshot();
......
...@@ -100,6 +100,7 @@ ...@@ -100,6 +100,7 @@
#include <QGraphicsWidget> #include <QGraphicsWidget>
#include <QGraphicsGridLayout> #include <QGraphicsGridLayout>
#include <QGraphicsProxyWidget> #include <QGraphicsProxyWidget>
#include <QGLFramebufferObjectFormat>
#include <QPainter> #include <QPainter>
#include <QPaintEngine> #include <QPaintEngine>
...@@ -2031,7 +2032,7 @@ void glViewer::slotPropertiesUpdated() { ...@@ -2031,7 +2032,7 @@ void glViewer::slotPropertiesUpdated() {
updateGL(); updateGL();
} }
void glViewer::snapshot(QImage& _image, int _width, int _height) { void glViewer::snapshot(QImage& _image, int _width, int _height, bool _alpha) {
int w = 0, h = 0, bak_w = 0, bak_h = 0; int w = 0, h = 0, bak_w = 0, bak_h = 0;
// Test if size is given: // Test if size is given:
...@@ -2057,18 +2058,37 @@ void glViewer::snapshot(QImage& _image, int _width, int _height) { ...@@ -2057,18 +2058,37 @@ void glViewer::snapshot(QImage& _image, int _width, int _height) {
glstate_->viewport(0, 0, w, h); glstate_->viewport(0, 0, w, h);
} }
QGLFramebufferObject fb( w, h, QGLFramebufferObject::CombinedDepthStencil); QGLFramebufferObjectFormat format;
format.setInternalTextureFormat(GL_RGBA);
format.setTextureTarget(GL_TEXTURE_2D);
format.setAttachment(QGLFramebufferObject::CombinedDepthStencil);
QGLFramebufferObject fb( w, h, format);
if ( fb.isValid() ){ if ( fb.isValid() ){
fb.bind(); fb.bind();
qApp->processEvents(); qApp->processEvents();
makeCurrent(); makeCurrent();
// Turn alpha on if demanded
ACG::Vec4f backColorBak;
ACG::Vec4f newBack;
if(_alpha) {
backColorBak = properties()->backgroundColor();
newBack = ACG::Vec4f(backColorBak[0], backColorBak[1], backColorBak[2], 0.0f);
properties()->backgroundColor(newBack);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
}
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
paintGL(); paintGL();
glFinish(); glFinish();
_image = fb.toImage().copy(scenePos().x(), scenePos().y(), w, h); // Reset alpha settings
if(_alpha)
properties()->backgroundColor(backColorBak);
_image = fb.toImage().copy(scenePos().x(), scenePos().y(), w, h);
} }
if(bak_w != 0 && bak_h != 0) { if(bak_w != 0 && bak_h != 0) {
...@@ -2077,12 +2097,12 @@ void glViewer::snapshot(QImage& _image, int _width, int _height) { ...@@ -2077,12 +2097,12 @@ void glViewer::snapshot(QImage& _image, int _width, int _height) {
} }
} }
void glViewer::snapshot( int _width, int _height ) void glViewer::snapshot( int _width, int _height, bool _alpha )
{ {
QImage image; QImage image;
// Capture image // Capture image
snapshot(image, _width, _height); snapshot(image, _width, _height, _alpha);
QFileInfo fi(properties_.snapshotName()); QFileInfo fi(properties_.snapshotName());
......
...@@ -765,10 +765,10 @@ private: ...@@ -765,10 +765,10 @@ private:
Save snapshot to file determined by snapshotBaseFileName() and Save snapshot to file determined by snapshotBaseFileName() and
the current snapshot counter. The \a back buffer will be saved. the current snapshot counter. The \a back buffer will be saved.
*/ */
virtual void snapshot(int _width = 0, int _height = 0); virtual void snapshot(int _width = 0, int _height = 0, bool _alpha = false);
/// Take a snapshot and store it in the given image /// Take a snapshot and store it in the given image
virtual void snapshot(QImage& _image, int _width = 0, int _height = 0); virtual void snapshot(QImage& _image, int _width = 0, int _height = 0, bool _alpha = false);
/** @} */ /** @} */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment