Permalink
Browse files

Improved the handling of command line parameters

  • Loading branch information...
1 parent 48accd9 commit 68d06ca44056b2e8b72c3815429d0858e1ecd997 @osg-training-guest osg-training-guest committed Jun 14, 2011
Showing with 22 additions and 15 deletions.
  1. +22 −15 examples/osgocclusionquery/osgocclusionquery.cpp
@@ -537,10 +537,10 @@ class KeyHandler : public osgGA::GUIEventHandler
}
else if (ea.getKey()=='o')
{
- if (osgDB::writeNodeFile( _node, "saved_model.osg" ))
- osg::notify( osg::ALWAYS ) << "osgOQ: Wrote scene graph to \"saved_model.osg\"" << std::endl;
+ if (osgDB::writeNodeFile( _node, "saved_model.osgt" ))
+ osg::notify( osg::ALWAYS ) << "osgOQ: Wrote scene graph to \"saved_model.osgt\"" << std::endl;
else
- osg::notify( osg::ALWAYS ) << "osgOQ: Wrote failed for \"saved_model.osg\"" << std::endl;
+ osg::notify( osg::ALWAYS ) << "osgOQ: Wrote failed for \"saved_model.osgt\"" << std::endl;
return true;
}
return false;
@@ -744,29 +744,36 @@ int main(int argc, char** argv)
// add the help handler
viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage()));
+ bool optimize = arguments.read( "--opt" );
// load the specified model
- osg::ref_ptr<osg::Node> root = osgDB::readNodeFiles( arguments );
- if (!root)
+ osg::ref_ptr<osg::Node> root = 0;
+
+ if (arguments.argc()>1)
{
- std::cout << arguments.getApplicationName() <<": No files specified, or can't load them." << std::endl;
- root = createStockScene().get();
- if (!root)
+ root = osgDB::readNodeFiles( arguments );
+ if (root.valid())
{
- std::cout << arguments.getApplicationName() <<": Failed to create stock scene." << std::endl;
+ // Run a NodeVisitor to insert OcclusionQueryNodes in the scene graph.
+ OcclusionQueryVisitor oqv;
+ root->accept( oqv );
+ }
+ else
+ {
+ std::cout << arguments.getApplicationName() <<": unable to load specified data." << std::endl;
return 1;
}
- std::cout << "Using stock scene instead." << std::endl;
}
else
{
- // Run a NodeVisitor to insert OcclusionQueryNodes in the scene graph.
- OcclusionQueryVisitor oqv;
- root->accept( oqv );
+ root = createStockScene().get();
+ if (!root)
+ {
+ std::cout << arguments.getApplicationName() <<": Failed to create stock scene." << std::endl;
+ return 1;
+ }
}
- bool optimize = arguments.read( "--opt" );
-
// any option left unread are converted into errors to write out later.
arguments.reportRemainingOptionsAsUnrecognized();

0 comments on commit 68d06ca

Please sign in to comment.