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
hemaoptima
Newbie


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

Hi,
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 rendered.how 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) );
camera->setProjectionMatrixAsPerspective(
30.0f, static_cast<double>(traits->width)/static_cast<double>(traits->height), 1.0f, 10000.0f );
camera->setClearMask( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
// 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!

Cheers,
y
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 Convert from screen space to world sp... NavyBas General 0 Thu Jun 22, 2017 6:14 pm View latest post
No new posts Disable rendering to screen wernerM General 0 Fri Apr 28, 2017 1:13 pm View latest post
No new posts Screen Space 2D Axis Alligned Boundin... Takarashy General 0 Tue Apr 11, 2017 8:31 pm View latest post
No new posts problem with shapefile height when lo... vinothrajendran4 General 2 Thu Feb 16, 2017 12:22 pm View latest post
No new posts Offline screen render without pbuffer... tnassour General 0 Wed Feb 15, 2017 7:29 am 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