OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

How to take screen shot of osgviewer

Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General [forum]
View previous topic :: View next topic  
Author Message

Joined: 01 Jul 2015
Posts: 8

PostPosted: Tue Sep 15, 2015 10:24 am    Post subject:
How to take screen shot of osgviewer
Reply with quote

i want to take screen shot of osgviewer and save it as .png. i referred to osgposter example. I am using osg and qt for my application. when i am trying to implemennt the same as shown in poster the image is not rendered properly.

this is the code im using .images are not properly can it be done .

QWidget* addViewWidget( osg::Camera* camera, osg::Node* scene )
// Poster arguments
bool activeMode = true;
bool outputPoster = true;
//bool outputTiles = false;
int tileWidth = 640, tileHeight = 480;
int posterWidth = 640*2, posterHeight = 480*2;
std::string posterName = "poster.png", extName = "png";
osg::Vec4 bgColor(0.2f, 0.2f, 0.6f, 1.0f);
osgViewer::View* view = new osgViewer::View;
view->setCamera( camera );
camera->addChild(scene); // added for poster
addView( view );
osg::Group *group = new osg::Group; // added for poster
group->addChild(camera); // added for poster
group->addChild(scene); // added for poster
osg::ref_ptr<PosterPrinter> printer = new PosterPrinter;
printer->setTileSize( tileWidth, tileHeight );
printer->setPosterSize( posterWidth, posterHeight );
printer->setCamera( camera );

osg::ref_ptr<osg::Image> posterImage = 0;
if ( outputPoster )
posterImage = new osg::Image;
posterImage->allocateImage( posterWidth, posterHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE );
printer->setFinalPoster( posterImage.get() );
printer->setOutputPosterName( posterName );
view->setSceneData( scene ); // added for poster
view->addEventHandler( new osgViewer::StatsHandler );
view->setCameraManipulator( new osgGA::TrackballManipulator );
view->addEventHandler( new PrintPosterHandler(printer.get()) );
osgQt::GraphicsWindowQt* gw = dynamic_cast<osgQt::GraphicsWindowQt*>( camera->getGraphicsContext() );
return gw ? gw->getGLWidget() : NULL;

osg::Camera* createCamera( int x, int y, int w, int h, const std::string& name="", bool windowDecoration=false )
osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->windowName = name;
traits->windowDecoration = windowDecoration;
traits->x = x;
traits->y = y;
traits->width = w;
traits->height = h;
traits->doubleBuffer = true;
traits->alpha = ds->getMinimumNumAlphaBits();
traits->stencil = ds->getMinimumNumStencilBits();
traits->sampleBuffers = ds->getMultiSamples();
traits->samples = ds->getNumMultiSamples();

osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setGraphicsContext( new osgQt::GraphicsWindowQt(traits.get()) );

camera->setClearColor( osg::Vec4(0.2, 0.2, 0.6, 1.0) );
camera->setViewport( new osg::Viewport(0, 0, traits->width, traits->height) );
30.0f, static_cast<double>(traits->width)/static_cast<double>(traits->height), 1.0f, 10000.0f );
// camera->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
// camera->setRenderOrder( osg::Camera::PRE_RENDER );
osg::Camera::RenderTargetImplementation renderImplementation = osg::Camera::FRAME_BUFFER;

camera->setRenderTargetImplementation( renderImplementation );
camera->setViewport( 0, 0, 640, 480 );
// camera->addChild( scene );

// Set the printer

return camera.release();


Thank you!

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General [forum] All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Duplicate 3dModel OSGviewer skehal General 0 Wed Aug 07, 2019 9:10 am View latest post
No new posts osgVIEWER problem camera skehal General 1 Tue Jul 23, 2019 9:17 am View latest post
No new posts Add/remove dynamically osg::View to o... innochenti General 0 Sat May 25, 2019 2:17 pm View latest post
No new posts off screen rendering with OSG Sorin General 0 Mon May 13, 2019 8:14 am View latest post
No new posts osgViewer GraphicsWindowX11 Event Han... ericstancliff General 3 Wed Apr 24, 2019 9:43 pm View latest post

Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP