From c0937c16140db75f6e48caf05e93ad839a9a173c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 14 Dec 2010 08:53:20 +0000 Subject: [PATCH] From Wang Rui, "A modified version is attached. The blank while generating is in fact used to avoid dual update traversals of the scene, which is not allowed in my application (but I forgot the reason ;-) Now the blank problem will disappear. Inactive mode is also available, using the --inactive mode and --camera-eye and --camera-hpr to set camera position: ./osgposter --output-poster --poster output.bmp --tilesize 800 600 --finalsize 8000 6000 cow.osg --inactive --camera-eye 0 0 20 " --- examples/osgposter/osgposter.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/examples/osgposter/osgposter.cpp b/examples/osgposter/osgposter.cpp index 4f72bd68b..f92514fe1 100644 --- a/examples/osgposter/osgposter.cpp +++ b/examples/osgposter/osgposter.cpp @@ -255,7 +255,7 @@ int main( int argc, char** argv ) int posterWidth = 640*2, posterHeight = 480*2; std::string posterName = "poster.bmp", extName = "bmp"; osg::Vec4 bgColor(0.2f, 0.2f, 0.6f, 1.0f); - osg::Camera::RenderTargetImplementation renderImplementation = osg::Camera::FRAME_BUFFER; + osg::Camera::RenderTargetImplementation renderImplementation = osg::Camera::FRAME_BUFFER_OBJECT; while ( arguments.read("--inactive") ) { activeMode = false; } while ( arguments.read("--color", bgColor.r(), bgColor.g(), bgColor.b()) ) {} @@ -330,16 +330,36 @@ int main( int argc, char** argv ) printer->setOutputPosterName( posterName ); } - // Create root and start the viewer +#if 0 + // While recording sub-images of the poster, the scene will always be traversed twice, from its two + // parent node: root and camera. Sometimes this may not be so comfortable. + // To prevent this behaviour, we can use a switch node to enable one parent and disable the other. + // However, the solution also needs to be used with care, as the window will go blank while taking + // snapshots and recover later. osg::ref_ptr root = new osg::Switch; root->addChild( scene, true ); root->addChild( camera.get(), false ); +#else + osg::ref_ptr root = new osg::Group; + root->addChild( scene ); + root->addChild( camera.get() ); +#endif osgViewer::Viewer viewer; - viewer.setUpViewInWindow( 100, 100, tileWidth, tileHeight ); viewer.setSceneData( root.get() ); viewer.getDatabasePager()->setDoPreCompile( false ); + if ( renderImplementation==osg::Camera::FRAME_BUFFER ) + { + // FRAME_BUFFER requires the window resolution equal or greater than the to-be-copied size + viewer.setUpViewInWindow( 100, 100, tileWidth, tileHeight ); + } + else + { + // We want to see the console output, so just render in a window + viewer.setUpViewInWindow( 100, 100, 800, 600 ); + } + if ( activeMode ) { viewer.addEventHandler( new PrintPosterHandler(printer.get()) );