#include "GLViewer_ViewFrame.h"
#include "GLViewer_Viewer.h"
#include "GLViewer_ViewPort2d.h"
-#include "GLViewer_FrameBuffer.h"
#include <QtxToolBar.h>
#include <QtxMultiAction.h>
QImage GLViewer_ViewFrame::dumpView()
{
GLViewer_ViewPort2d* aViewPort = ((GLViewer_ViewPort2d*)myVP);
- int aWidth = aViewPort->getWidth();
- int aHeight = aViewPort->getHeight();
-
- GLViewer_FrameBuffer aFrameBuffer;
- if( aFrameBuffer.init( aWidth, aHeight ) )
- {
- glPushAttrib( GL_VIEWPORT_BIT );
- glViewport( 0, 0, aWidth, aHeight );
- aFrameBuffer.bind();
-
- // draw scene
- aViewPort->getGLWidget()->updateGL();
-
- aFrameBuffer.unbind();
- glPopAttrib();
-
- QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
-
- aFrameBuffer.bind();
-
- glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
-
- aFrameBuffer.unbind();
-
- anImage = anImage.rgbSwapped();
- anImage = anImage.mirrored();
+ QImage anImage = aViewPort->dumpContents( false );
+ if( !anImage.isNull() )
return anImage;
- }
- QImage anImage;
GLViewer_Widget* aWidget = aViewPort->getGLWidget();
if ( aWidget )
anImage = aWidget->grabFrameBuffer();
#include "GLViewer_Compass.h"
#include "GLViewer_Grid.h"
#include "GLViewer_Drawer.h"
+#include "GLViewer_FrameBuffer.h"
#include <QtxToolTip.h>
}
}
}
+
+/*!
+ Dumps contents of the scene
+ \param theWholeScene - flag, allowing to dump the whole scene,
+ not only its visible regeion
+ \return image with the scene contents
+*/
+QImage GLViewer_ViewPort2d::dumpContents( bool theWholeScene )
+{
+ QImage aResult;
+
+ int aWidth = theWholeScene ? myBorder->width() : myWidth;
+ int aHeight = theWholeScene ? myBorder->height() : myHeight;
+
+ // try to initialize framebuffer
+ GLViewer_FrameBuffer aFrameBuffer;
+ if( !aFrameBuffer.init( aWidth, aHeight ) )
+ return aResult;
+
+ if( theWholeScene )
+ {
+ glMatrixMode( GL_PROJECTION );
+ glPushMatrix();
+ glLoadIdentity();
+ glOrtho( -aWidth/2, aWidth/2, -aHeight/2, aHeight/2, -100, 100 );
+
+ glPushAttrib( GL_VIEWPORT_BIT );
+ glViewport( 0, 0, aWidth, aHeight );
+ }
+
+ // bind the framebuffer
+ aFrameBuffer.bind();
+
+ if( theWholeScene )
+ {
+ // centre the scene and reset the scale
+ int aXOffset = myBorder->left();
+ int aYOffset = myBorder->bottom();
+ myGLWidget->setPan( -aWidth/2 - aXOffset, -aHeight/2 - aYOffset, 0.0 );
+ myGLWidget->setScale( 1.0, 1.0, 1.0 );
+ }
+
+ // draw the scene to the framebuffer
+ myGLWidget->updateGL();
+
+ // unbind the framebuffer
+ aFrameBuffer.unbind();
+
+ if( theWholeScene )
+ {
+ glPopAttrib(); // GL_VIEWPORT_BIT
+
+ glMatrixMode( GL_PROJECTION );
+ glPopMatrix();
+ glMatrixMode( GL_MODELVIEW );
+ glPopMatrix();
+ }
+
+ // get an image by reading pixels from the framebuffer
+ QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
+
+ aFrameBuffer.bind();
+ glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
+ aFrameBuffer.unbind();
+
+ if( theWholeScene )
+ {
+ // restore the scene parameters
+ myGLWidget->setPan( myXPan, myYPan, 0.0 );
+ myGLWidget->setScale( myXScale, myYScale, 1.0 );
+ myGLWidget->updateGL();
+ }
+
+ anImage = anImage.rgbSwapped();
+ anImage = anImage.mirrored();
+
+ return anImage;
+}
* Class GLViewer_ViewPort
* 2D visualisation canvas of GLViewer
*/
-class GLViewer_ViewPort2d: public GLViewer_ViewPort
+class GLVIEWER_API GLViewer_ViewPort2d: public GLViewer_ViewPort
{
Q_OBJECT
friend class GLViewer_Widget;
//! Transforms global rect to window rect
QRect GLV2win( const GLViewer_Rect& ) const;
+ //! Dumps contents of the scene
+ QImage dumpContents( bool theWholeScene = false );
+
signals:
//! Emits after any transformation
void vpUpdateValues();