diff --git a/Make/makedirdefs b/Make/makedirdefs index 9b16c0875..9967d3330 100644 --- a/Make/makedirdefs +++ b/Make/makedirdefs @@ -111,7 +111,6 @@ DEMOS_DIRS = \ osggeometry\ osghangglide\ osghud\ - osgtext\ osgimpostor\ osglight\ osglightpoint\ @@ -120,13 +119,14 @@ DEMOS_DIRS = \ osgoccluder\ osgparticle\ osgprerender\ - osgshadowtexture\ osgreflect\ osgscribe\ osgsequence\ + osgshadowtexture\ osgshape\ osgstereoimage\ osgteapot\ + osgtext\ osgtexture1D\ osgtexture2D\ osgtexture3D\ diff --git a/NEWS.txt b/NEWS.txt index ba26656a2..8a5cdf098 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -3,6 +3,12 @@ OSG News (most significant items from ChangeLog) ================================================ + Improvemnts to the Makefle system. + + Added support for early abort of rendering, useful for interactive + applications which occasional have rendering that takes that long + enough (i.e. several second) that end users may wish to abort + during the drawing. Improved thread safety when working multipipe systems. @@ -10,7 +16,7 @@ OSG News (most significant items from ChangeLog) New MD2 plugin - New osgText implementions. + New thread safe osgText implemention. 24th January 2003 - OpenSceneGraph-0.9.3.tar.gz diff --git a/include/osg/DisplaySettings b/include/osg/DisplaySettings index 3177dc551..807a9bfb8 100644 --- a/include/osg/DisplaySettings +++ b/include/osg/DisplaySettings @@ -42,11 +42,11 @@ class SG_EXPORT DisplaySettings : public osg::Referenced readEnvironmentalVariables(); } - DisplaySettings(std::vector& commandLine) + DisplaySettings(ArgumentParser& arguments) { setDefaults(); readEnvironmentalVariables(); - readCommandLine(commandLine); + readCommandLine(arguments); } DisplaySettings(const DisplaySettings& vs); @@ -61,12 +61,8 @@ class SG_EXPORT DisplaySettings : public osg::Referenced void readEnvironmentalVariables(); - /** read the command line string list, removing any matched control sequences.*/ - void readCommandLine(std::vector& commandLine); - /** read the commandline arguments.*/ - void readCommandLine(ArgumentParser& parser); - + void readCommandLine(ArgumentParser& arguments); void setStereo(bool on) { _stereo = on; } diff --git a/include/osgDB/Registry b/include/osgDB/Registry index e9849c0ae..9dbc68a32 100644 --- a/include/osgDB/Registry +++ b/include/osgDB/Registry @@ -51,9 +51,6 @@ class OSGDB_EXPORT Registry : public osg::Referenced static Registry* instance(); - /** read the command line string list, removing any matched control sequences.*/ - void readCommandLine(std::vector& commandLine); - /** read the command line arguments.*/ void readCommandLine(osg::ArgumentParser& commandLine); @@ -201,12 +198,6 @@ class OSGDB_EXPORT Registry : public osg::Referenced }; -/** read the command line string list into the osgDB::Registry(), removing any matched control sequences.*/ -inline void readCommandLine(std::vector& commandLine) -{ - Registry::instance()->readCommandLine(commandLine); -} - /** read the command line arguments.*/ inline void readCommandLine(osg::ArgumentParser& parser) { diff --git a/include/osgGLUT/Viewer b/include/osgGLUT/Viewer index c2a042416..c9920c123 100644 --- a/include/osgGLUT/Viewer +++ b/include/osgGLUT/Viewer @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -46,8 +47,13 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgGA::GUIActionAdapter public: Viewer(); + Viewer(osg::ArgumentParser& arguments); + virtual ~Viewer(); + /** read the command line string list, removing any matched control sequences.*/ + void readCommandLine(osg::ArgumentParser& arguments); + /** init is deprecated, you should use addViewport instead. init is * only available for backwards compatibility.*/ virtual void init(osg::Node* rootnode); @@ -108,8 +114,6 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgGA::GUIActionAdapter /// Toggle fullscreen virtual void toggleFullScreen(); - /** read the command line string list, removing any matched control sequences.*/ - void readCommandLine(std::vector& commandLine); void setDisplaySettings(osg::DisplaySettings* ds) { _displaySettings = ds; } osg::DisplaySettings* getDisplaySettings() { return _displaySettings.get(); } @@ -129,6 +133,8 @@ class OSGGLUT_EXPORT Viewer : public Window, public osgGA::GUIActionAdapter int mapWindowXYToViewport(int x, int y); protected: + + void initialize(); virtual void clear(); diff --git a/src/Demos/osganimate/osganimate.cpp b/src/Demos/osganimate/osganimate.cpp index 55e1f25d1..8ca5ec5fb 100644 --- a/src/Demos/osganimate/osganimate.cpp +++ b/src/Demos/osganimate/osganimate.cpp @@ -12,8 +12,6 @@ #include #include - -#include #include @@ -190,26 +188,32 @@ osg::Node* createModel() int main( int argc, char **argv ) { + // use an ArgumentParser object to manage the program arguments. + osg::ArgumentParser arguments(&argc,argv); - // initialize the GLUT - glutInit( &argc, argv ); - - // create the commandline args. - std::vector commandLine; - for(int i=1;isetCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); // initialize the viewer. - osgGLUT::Viewer viewer; - viewer.setWindowTitle(argv[0]); + osgGLUT::Viewer viewer(arguments); - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); - - // configure the plugin registry from the commandline arguments, and - // eat any parameters that have been matched. - osgDB::readCommandLine(commandLine); + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout); + return 1; + } + + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } // load the nodes from the commandline arguments. osg::Node* model = createModel(); diff --git a/src/Demos/osgbillboard/osgbillboard.cpp b/src/Demos/osgbillboard/osgbillboard.cpp index 619c7d86e..afb3415b3 100644 --- a/src/Demos/osgbillboard/osgbillboard.cpp +++ b/src/Demos/osgbillboard/osgbillboard.cpp @@ -165,25 +165,32 @@ osg::Node* createModel() int main( int argc, char **argv ) { - // initialize the GLUT - glutInit( &argc, argv ); - - // create the commandline args. - std::vector commandLine; - for(int i=1;isetCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + // initialize the viewer. - osgGLUT::Viewer viewer; - viewer.setWindowTitle(argv[0]); + osgGLUT::Viewer viewer(arguments); - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); - - // configure the plugin registry from the commandline arguments, and - // eat any parameters that have been matched. - osgDB::readCommandLine(commandLine); + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout); + return 1; + } + + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } // create a model from the images. osg::Node* rootNode = createModel(); diff --git a/src/Demos/osgcallback/osgcallback.cpp b/src/Demos/osgcallback/osgcallback.cpp index 4aed79acb..c373667b9 100644 --- a/src/Demos/osgcallback/osgcallback.cpp +++ b/src/Demos/osgcallback/osgcallback.cpp @@ -1,5 +1,3 @@ -#include -#include #include #include @@ -15,39 +13,8 @@ #include #include - #include -void write_usage(std::ostream& out,const std::string& name) -{ - out << std::endl; - out <<"usage:"<< std::endl; - out <<" "< commandLine; - for(int i=1;isetCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + // initialize the viewer. - osgGLUT::Viewer viewer; - viewer.setWindowTitle(argv[0]); + osgGLUT::Viewer viewer(arguments); - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); - - // configure the plugin registry from the commandline arguments, and - // eat any parameters that have been matched. - osgDB::readCommandLine(commandLine); + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout); + return 1; + } + + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } // load the nodes from the commandline arguments. - osg::Node* rootnode = osgDB::readNodeFiles(commandLine); + osg::Node* rootnode = osgDB::readNodeFiles(arguments); if (!rootnode) { // write_usage(osg::notify(osg::NOTICE),argv[0]); diff --git a/src/Demos/osgclip/osgclip.cpp b/src/Demos/osgclip/osgclip.cpp index e61e0dfca..d245a574f 100644 --- a/src/Demos/osgclip/osgclip.cpp +++ b/src/Demos/osgclip/osgclip.cpp @@ -17,7 +17,6 @@ #include #include -#include #include #include @@ -128,34 +127,35 @@ osg::Node* decorate_with_clip_node(osg::Node* subgraph) int main( int argc, char **argv ) { - // initialize the GLUT - glutInit( &argc, argv ); - - if (argc<2) - { - write_usage(osg::notify(osg::NOTICE),argv[0]); - return 0; - } - - // create the commandline args. - std::vector commandLine; - for(int i=1;isetCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + // initialize the viewer. - osgGLUT::Viewer viewer; - viewer.setWindowTitle(argv[0]); - - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); - - // configure the plugin registry from the commandline arguments, and - // eat any parameters that have been matched. - osgDB::readCommandLine(commandLine); + osgGLUT::Viewer viewer(arguments); + + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout); + return 1; + } + + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } // load the nodes from the commandline arguments. - osg::Node* loadedModel = osgDB::readNodeFiles(commandLine); + osg::Node* loadedModel = osgDB::readNodeFiles(arguments); if (!loadedModel) { write_usage(osg::notify(osg::NOTICE),argv[0]); diff --git a/src/Demos/osgcopy/osgcopy.cpp b/src/Demos/osgcopy/osgcopy.cpp index 4af4b5559..c3e1fa504 100644 --- a/src/Demos/osgcopy/osgcopy.cpp +++ b/src/Demos/osgcopy/osgcopy.cpp @@ -18,40 +18,8 @@ #include -void write_usage(std::ostream& out,const std::string& name) -{ - out << std::endl; - out <<"usage:"<< std::endl; - out <<" "< commandLine; - for(int i=1;isetCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + // initialize the viewer. - osgGLUT::Viewer viewer; - viewer.setWindowTitle(argv[0]); - - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); - - // configure the plugin registry from the commandline arguments, and - // eat any parameters that have been matched. - osgDB::readCommandLine(commandLine); + osgGLUT::Viewer viewer(arguments); + + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout); + return 1; + } + + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } // load the nodes from the commandline arguments. - osg::Node* rootnode = osgDB::readNodeFiles(commandLine); + osg::Node* rootnode = osgDB::readNodeFiles(arguments); if (!rootnode) { - write_usage(osg::notify(osg::NOTICE),argv[0]); return 1; } diff --git a/src/Demos/osgcube/osgcube.cpp b/src/Demos/osgcube/osgcube.cpp index b7f635d44..5cdf09aeb 100644 --- a/src/Demos/osgcube/osgcube.cpp +++ b/src/Demos/osgcube/osgcube.cpp @@ -7,7 +7,6 @@ #include #include -#include #include @@ -160,23 +159,33 @@ osg::Geode* createGeometryCube() int main( int argc, char **argv ) { + // use an ArgumentParser object to manage the program arguments. + osg::ArgumentParser arguments(&argc,argv); - glutInit( &argc, argv ); + // set up the usage document, in case we need to print out how to use this program. + arguments.getApplicationUsage()->setCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + + // initialize the viewer. + osgGLUT::Viewer viewer(arguments); - // create the commandline args. - std::vector commandLine; - for(int i=1;iwrite(std::cout); + return 1; + } - // create the viewer and the model to it. - osgGLUT::Viewer viewer; + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); - viewer.setWindowTitle(argv[0]); - - - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); - + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } + osg::MatrixTransform* myTransform = new osg::MatrixTransform(); myTransform->addChild( createGeometryCube() ); diff --git a/src/Demos/osgcubemap/osgcubemap.cpp b/src/Demos/osgcubemap/osgcubemap.cpp index 006def8fd..be0caeb05 100644 --- a/src/Demos/osgcubemap/osgcubemap.cpp +++ b/src/Demos/osgcubemap/osgcubemap.cpp @@ -17,44 +17,11 @@ #include #include -#include #include #include #include -void write_usage(std::ostream& out, const std::string& name) -{ - out << std::endl; - out <<"usage:"<< std::endl; - out <<" "<getOrCreateStateSet(); @@ -103,32 +70,35 @@ void create_specular_highlights(osg::Node *node) int main(int argc, char *argv[]) { - // initialize the GLUT - glutInit( &argc, argv ); - - if (argc<2) { - write_usage(std::cout, argv[0]); - return 0; - } - - // create the commandline args. - std::vector commandLine; - for(int i=1; isetCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + // initialize the viewer. - osgGLUT::Viewer viewer; - viewer.setWindowTitle(argv[0]); + osgGLUT::Viewer viewer(arguments); - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); - - // configure the plugin registry from the commandline arguments, and - // eat any parameters that have been matched. - osgDB::readCommandLine(commandLine); + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout); + return 1; + } + + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } // load the nodes from the commandline arguments. - osg::Node* rootnode = osgDB::readNodeFiles(commandLine); + osg::Node* rootnode = osgDB::readNodeFiles(arguments); if (!rootnode) { return 1; } diff --git a/src/Demos/osggeodemo/osggeodemo.cpp b/src/Demos/osggeodemo/osggeodemo.cpp index 8bc12e745..daa772135 100644 --- a/src/Demos/osggeodemo/osggeodemo.cpp +++ b/src/Demos/osggeodemo/osggeodemo.cpp @@ -26,41 +26,6 @@ // geo loader and having direct links with it. #include "../../osgPlugins/geo/osgGeoAnimation.h" -void write_usage(std::ostream& out,const std::string& name) -{ - out << std::endl; - out <<"usage:"<< std::endl; - out <<" "<setCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + arguments.getApplicationUsage()->addCommandLineOption("-p ","Use specificed animation path file for camera animation"); + + // read the commandline args. std::string pathfile; + while (arguments.read("-p",pathfile)) {} + float camera_fov=-1; - - // initialize the GLUT - glutInit( &argc, argv ); - - if (argc<2) - { - write_usage(std::cout,argv[0]); - return 1; - } - - // create the commandline args. - std::vector commandLine; - for(int i=1;i= argc ) { - write_usage( std::cout, argv[0]); - return 1; - } - else - pathfile = std::string(argv[++i]); - } else if( std::string(argv[i]) == "-fov" ) { - camera_fov=atof(argv[i+1]); - ++i; // skip the value - } - else - commandLine.push_back(argv[i]); - } + while (arguments.read("-fov",camera_fov)) {} // initialize the viewer. - osgGLUT::Viewer viewer; - viewer.setWindowTitle(argv[0]); - - - // get the path of the executable and use it to set internal data and library paths. - std::string executablePath = osgDB::getFilePath(argv[0]); - if (!executablePath.empty()) + osgGLUT::Viewer viewer(arguments); + + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) { - osg::notify(osg::NOTICE) << "Adding executable path '"<write(std::cout); + return 1; + } + + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; } - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); - - // configure the plugin registry from the commandline arguments, and - // eat any parameters that have been matched. - osgDB::readCommandLine(commandLine); // load the nodes from the commandline arguments. - osg::Node* rootnode = osgDB::readNodeFiles(commandLine); + osg::Node* rootnode = osgDB::readNodeFiles(arguments); if (!rootnode) { - write_usage(osg::notify(osg::NOTICE),argv[0]); return 1; } diff --git a/src/Demos/osggeometry/osggeometry.cpp b/src/Demos/osggeometry/osggeometry.cpp index 12cbe3a99..9e59f8538 100644 --- a/src/Demos/osggeometry/osggeometry.cpp +++ b/src/Demos/osggeometry/osggeometry.cpp @@ -13,7 +13,6 @@ #include #include -#include #include @@ -643,20 +642,32 @@ osg::Node* createBackground() int main( int argc, char **argv ) { + // use an ArgumentParser object to manage the program arguments. + osg::ArgumentParser arguments(&argc,argv); - glutInit( &argc, argv ); + // set up the usage document, in case we need to print out how to use this program. + arguments.getApplicationUsage()->setCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); - // create the commandline args. - std::vector commandLine; - for(int i=1;iwrite(std::cout); + return 1; + } - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } // create the model diff --git a/src/Demos/osghangglide/osghangglide.cpp b/src/Demos/osghangglide/osghangglide.cpp index c6a4f4a4c..ce3ae4469 100644 --- a/src/Demos/osghangglide/osghangglide.cpp +++ b/src/Demos/osghangglide/osghangglide.cpp @@ -12,7 +12,6 @@ #include -#include #include #include "GliderManipulator.h" @@ -104,26 +103,36 @@ osg::Group* createModel() int main( int argc, char **argv ) { - glutInit( &argc, argv ); - // create the commandline args. - std::vector commandLine; - for(int i=1;isetCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); // initialize the viewer. - osgGLUT::Viewer viewer; - viewer.setWindowTitle(argv[0]); - - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); - - // configure the plugin registry from the commandline arguments, and - // eat any parameters that have been matched. - osgDB::readCommandLine(commandLine); + osgGLUT::Viewer viewer(arguments); + + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout); + return 1; + } + + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } // load the nodes from the commandline arguments. - osg::Node* rootnode = osgDB::readNodeFiles(commandLine); + osg::Node* rootnode = osgDB::readNodeFiles(arguments); if (!rootnode) rootnode = createModel(); viewer.addViewport( rootnode ); diff --git a/src/Demos/osghud/osghud.cpp b/src/Demos/osghud/osghud.cpp index b10e0119d..043c49b60 100644 --- a/src/Demos/osghud/osghud.cpp +++ b/src/Demos/osghud/osghud.cpp @@ -1,5 +1,3 @@ -#include -#include #include #include @@ -24,37 +22,6 @@ #include -void write_usage(std::ostream& out,const std::string& name) -{ - out << std::endl; - out <<"usage:"<< std::endl; - out <<" "< commandLine; - for(int i=1;isetCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); // initialize the viewer. - osgGLUT::Viewer viewer; - viewer.setWindowTitle(argv[0]); + osgGLUT::Viewer viewer(arguments); + + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout); + return 1; + } + + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); - - // configure the plugin registry from the commandline arguments, and - // eat any parameters that have been matched. - osgDB::readCommandLine(commandLine); // load the nodes from the commandline arguments. - osg::Node* rootnode = osgDB::readNodeFiles(commandLine); + osg::Node* rootnode = osgDB::readNodeFiles(arguments); if (!rootnode) { // write_usage(osg::notify(osg::NOTICE),argv[0]); diff --git a/src/Demos/osgimpostor/osgimpostor.cpp b/src/Demos/osgimpostor/osgimpostor.cpp index a73bd6315..700fe16dd 100644 --- a/src/Demos/osgimpostor/osgimpostor.cpp +++ b/src/Demos/osgimpostor/osgimpostor.cpp @@ -225,11 +225,11 @@ int main( int argc, char **argv ) viewer.setWindowTitle(argv[0]); // create the commandline args. - std::vector commandLine; - for(int i=1;i arguments; + for(int i=1;i -#include #include #include @@ -301,29 +299,36 @@ osg::Node* createRoom(osg::Node* loadedModel) int main( int argc, char **argv ) { + // use an ArgumentParser object to manage the program arguments. + osg::ArgumentParser arguments(&argc,argv); - // initialize the GLUT - glutInit( &argc, argv ); - - // create the commandline args. - std::vector commandLine; - for(int i=1;isetCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); // initialize the viewer. - osgGLUT::Viewer viewer; - viewer.setWindowTitle(argv[0]); + osgGLUT::Viewer viewer(arguments); + + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout); + return 1; + } + + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); - - // configure the plugin registry from the commandline arguments, and - // eat any parameters that have been matched. - osgDB::readCommandLine(commandLine); // load the nodes from the commandline arguments. - osg::Node* loadedModel = osgDB::readNodeFiles(commandLine); + osg::Node* loadedModel = osgDB::readNodeFiles(arguments); // create a room made of foor walls, a floor, a roof, and swinging light fitting. osg::Node* rootnode = createRoom(loadedModel); diff --git a/src/Demos/osglightpoint/osglightpoint.cpp b/src/Demos/osglightpoint/osglightpoint.cpp index 4c4955919..976d1b062 100644 --- a/src/Demos/osglightpoint/osglightpoint.cpp +++ b/src/Demos/osglightpoint/osglightpoint.cpp @@ -20,37 +20,6 @@ #include -void write_usage(std::ostream& out,const std::string& name) -{ - out << std::endl; - out <<"usage:"<< std::endl; - out <<" "< commandLine; - for(int i=1;isetCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); // initialize the viewer. - osgGLUT::Viewer viewer; - viewer.setWindowTitle(argv[0]); + osgGLUT::Viewer viewer(arguments); + + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout); + return 1; + } + + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); - - // configure the plugin registry from the commandline arguments, and - // eat any parameters that have been matched. - osgDB::readCommandLine(commandLine); osg::Group* rootnode = new osg::Group; // load the nodes from the commandline arguments. - rootnode->addChild(osgDB::readNodeFiles(commandLine)); + rootnode->addChild(osgDB::readNodeFiles(arguments)); rootnode->addChild(createLightPointsDatabase()); if (!rootnode) { diff --git a/src/Demos/osglogo/osglogo.cpp b/src/Demos/osglogo/osglogo.cpp index b96ad8918..ee77cbb6a 100644 --- a/src/Demos/osglogo/osglogo.cpp +++ b/src/Demos/osglogo/osglogo.cpp @@ -17,7 +17,6 @@ #include #include -#include #include @@ -404,24 +403,35 @@ osg::Node* createLogo() int main( int argc, char **argv ) { - glutInit( &argc, argv ); + // use an ArgumentParser object to manage the program arguments. + osg::ArgumentParser arguments(&argc,argv); - // create the commandline args. - std::vector commandLine; - for(int i=1;isetCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + arguments.getApplicationUsage()->addCommandLineOption("ps","Render the Professional Services logo"); + + // initialize the viewer. + osgGLUT::Viewer viewer(arguments); - // create the viewer and the model to it. - osgGLUT::Viewer viewer; - - viewer.setWindowTitle(argv[0]); - - - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout); + return 1; + } + if (arguments.find("ps")) s_ProfessionalServices = true; - if (std::find(commandLine.begin(),commandLine.end(),std::string("ps"))!=commandLine.end()) s_ProfessionalServices = true; + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } osg::Node* node = createLogo(); diff --git a/src/Demos/osgmultitexture/osgmultitexture.cpp b/src/Demos/osgmultitexture/osgmultitexture.cpp index 7b7c00978..a6d733a18 100644 --- a/src/Demos/osgmultitexture/osgmultitexture.cpp +++ b/src/Demos/osgmultitexture/osgmultitexture.cpp @@ -1,5 +1,3 @@ -#include -#include #include #include @@ -15,72 +13,40 @@ #include #include - #include -void write_usage(std::ostream& out,const std::string& name) -{ - out << std::endl; - out <<"usage:"<< std::endl; - out <<" "< commandLine; - for(int i=1;isetCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + // initialize the viewer. - osgGLUT::Viewer viewer; - viewer.setWindowTitle(argv[0]); + osgGLUT::Viewer viewer(arguments); - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); - - // configure the plugin registry from the commandline arguments, and - // eat any parameters that have been matched. - osgDB::readCommandLine(commandLine); + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout); + return 1; + } + + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } // load the nodes from the commandline arguments. - osg::Node* rootnode = osgDB::readNodeFiles(commandLine); + osg::Node* rootnode = osgDB::readNodeFiles(arguments); if (!rootnode) { // write_usage(osg::notify(osg::NOTICE),argv[0]); diff --git a/src/Demos/osgoccluder/osgoccluder.cpp b/src/Demos/osgoccluder/osgoccluder.cpp index 05082c11d..aee2c3ac2 100644 --- a/src/Demos/osgoccluder/osgoccluder.cpp +++ b/src/Demos/osgoccluder/osgoccluder.cpp @@ -1,5 +1,3 @@ -#include -#include #include #include @@ -23,45 +21,6 @@ #include #include -void write_usage(std::ostream& out,const std::string& name) -{ - out << std::endl; - out <<"usage:"<< std::endl; - out <<" "< commandLine; - for(int i=1;i::iterator itr=std::find(commandLine.begin(),commandLine.end(),std::string("-c")); - if (itr!=commandLine.end()) - { - manuallyCreateImpostors = true; - commandLine.erase(itr); - } + // use an ArgumentParser object to manage the program arguments. + osg::ArgumentParser arguments(&argc,argv); + // set up the usage document, in case we need to print out how to use this program. + arguments.getApplicationUsage()->setCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + arguments.getApplicationUsage()->addCommandLineOption("-c","Mannually create occluders"); + // initialize the viewer. - osgGLUT::Viewer viewer; - viewer.setWindowTitle(argv[0]); + osgGLUT::Viewer viewer(arguments); - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); - - // configure the plugin registry from the commandline arguments, and - // eat any parameters that have been matched. - osgDB::readCommandLine(commandLine); + bool manuallyCreateOccluders = false; + while (arguments.read("-c")) { manuallyCreateOccluders = true; } + + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout); + return 1; + } + + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } // load the nodes from the commandline arguments. - osg::Node* loadedmodel = osgDB::readNodeFiles(commandLine); + osg::Node* loadedmodel = osgDB::readNodeFiles(arguments); if (!loadedmodel) { // write_usage(osg::notify(osg::NOTICE),argv[0]); @@ -369,7 +325,7 @@ int main( int argc, char **argv ) // add the occluders to the loaded model. osg::Group* rootnode = NULL; - if (manuallyCreateImpostors) + if (manuallyCreateOccluders) { rootnode = new osg::Group; rootnode->addChild(loadedmodel); @@ -388,7 +344,7 @@ int main( int argc, char **argv ) viewer.registerCameraManipulator(new osgGA::FlightManipulator); viewer.registerCameraManipulator(new osgGA::DriveManipulator); - if (manuallyCreateImpostors) + if (manuallyCreateOccluders) { viewer.prependEventHandler(new OccluderEventHandler(viewer.getViewportSceneView(0),rootnode)); } diff --git a/src/Demos/osgpbuffer/osgpbuffer.cpp b/src/Demos/osgpbuffer/osgpbuffer.cpp index 292dbce3d..b87b5c788 100644 --- a/src/Demos/osgpbuffer/osgpbuffer.cpp +++ b/src/Demos/osgpbuffer/osgpbuffer.cpp @@ -601,8 +601,8 @@ int main( int argc, char **argv ) } // create the commandline args. - std::vector commandLine; - for(int i=1;i arguments; + for(int i=1;i #include -#include #include class MyUpdateCallback : public osg::NodeCallback @@ -364,70 +363,38 @@ osg::Node* createPreRenderSubGraph(osg::Node* subgraph) return parent; } -void write_usage(std::ostream& out,const std::string& name) -{ - out << std::endl; - out <<"usage:"<< std::endl; - out <<" "<setCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + + // initialize the viewer. + osgGLUT::Viewer viewer(arguments); - if (argc<2) + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) { - write_usage(osg::notify(osg::NOTICE),argv[0]); - return 0; + arguments.getApplicationUsage()->write(std::cout); + return 1; } - // create the commandline args. - std::vector commandLine; - for(int i=1;i #include -#include #include @@ -307,34 +306,35 @@ osg::Node* createMirroredScene(osg::Node* model) int main( int argc, char **argv ) { - // initialize the GLUT - glutInit( &argc, argv ); + // use an ArgumentParser object to manage the program arguments. + osg::ArgumentParser arguments(&argc,argv); - if (argc<2) + // set up the usage document, in case we need to print out how to use this program. + arguments.getApplicationUsage()->setCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + + // initialize the viewer. + osgGLUT::Viewer viewer(arguments); + + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) { - //write_usage(osg::notify(osg::NOTICE),argv[0]); - return 0; + arguments.getApplicationUsage()->write(std::cout); + return 1; } - // create the commandline args. - std::vector commandLine; - for(int i=1;i -void write_usage(std::ostream& out,const std::string& name) -{ - out << std::endl; - out <<"usage:"<< std::endl; - out <<" "< commandLine; - for(int i=1;isetCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + // initialize the viewer. - osgGLUT::Viewer viewer; - viewer.setWindowTitle(argv[0]); - - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); - - // configure the plugin registry from the commandline arguments, and - // eat any parameters that have been matched. - osgDB::readCommandLine(commandLine); + osgGLUT::Viewer viewer(arguments); + + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout); + return 1; + } + + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } // load the nodes from the commandline arguments. - osg::Node* loadedModel = osgDB::readNodeFiles(commandLine); + osg::Node* loadedModel = osgDB::readNodeFiles(arguments); if (!loadedModel) { - write_usage(osg::notify(osg::NOTICE),argv[0]); return 1; } diff --git a/src/Demos/osgsequence/osgsequence.cpp b/src/Demos/osgsequence/osgsequence.cpp index aa708e622..55f2ffce5 100644 --- a/src/Demos/osgsequence/osgsequence.cpp +++ b/src/Demos/osgsequence/osgsequence.cpp @@ -9,7 +9,6 @@ #include #include -#include // @@ -69,25 +68,6 @@ private: std::vector* _seq; }; -void write_usage(std::ostream& out, const std::string& name) -{ - out << std::endl; - out <<"usage:"<< std::endl; - out <<" "<& model) @@ -114,39 +94,44 @@ osg::Sequence* generateSeq(osg::Sequence::LoopMode mode, int main( int argc, char **argv ) { - // initialize the GLUT - glutInit( &argc, argv ); + // use an ArgumentParser object to manage the program arguments. + osg::ArgumentParser arguments(&argc,argv); - if (argc < 2) + // set up the usage document, in case we need to print out how to use this program. + arguments.getApplicationUsage()->setCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + + // initialize the viewer. + osgGLUT::Viewer viewer(arguments); + + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) { - write_usage(osg::notify(osg::NOTICE), argv[0]); - return 0; + arguments.getApplicationUsage()->write(std::cout); + return 1; } - // create commandline args - std::vector commandLine; - for (int ia = 1; ia < argc; ia++) - commandLine.push_back(argv[ia]); + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); - // initialize the viewer - osgGLUT::Viewer viewer; - viewer.setWindowTitle(argv[0]); - - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } // assumes any remaining parameters are models std::vector model; - unsigned int i; - for (i = 0; i < commandLine.size(); i++) { - std::cerr << "Loading " << commandLine[i] << std::endl; - osg::Node* node = osgDB::readNodeFile(commandLine[i]); + int i; + for (i = 1; i < arguments.argc(); i++) + { + std::cerr << "Loading " << arguments[i] << std::endl; + osg::Node* node = osgDB::readNodeFile(arguments[i]); if (node) model.push_back(node); } if (model.empty()) { - write_usage(osg::notify(osg::NOTICE),argv[0]); return -1; } diff --git a/src/Demos/osgshadowtexture/osgshadowtexture.cpp b/src/Demos/osgshadowtexture/osgshadowtexture.cpp index bdfc517f5..dc7bb8ddf 100644 --- a/src/Demos/osgshadowtexture/osgshadowtexture.cpp +++ b/src/Demos/osgshadowtexture/osgshadowtexture.cpp @@ -15,7 +15,6 @@ #include -#include #include @@ -172,25 +171,32 @@ osg::Node* createModel() int main( int argc, char **argv ) { - // initialize the GLUT - glutInit( &argc, argv ); - - // create the commandline args. - std::vector commandLine; - for(int i=1;isetCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + // initialize the viewer. - osgGLUT::Viewer viewer; - viewer.setWindowTitle(argv[0]); + osgGLUT::Viewer viewer(arguments); - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); - - // configure the plugin registry from the commandline arguments, and - // eat any parameters that have been matched. - osgDB::readCommandLine(commandLine); + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout); + return 1; + } + + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } // load the nodes from the commandline arguments. osg::Node* model = createModel(); diff --git a/src/Demos/osgshape/osgshape.cpp b/src/Demos/osgshape/osgshape.cpp index 00687a985..868e1aaa1 100644 --- a/src/Demos/osgshape/osgshape.cpp +++ b/src/Demos/osgshape/osgshape.cpp @@ -6,7 +6,6 @@ #include #include -#include #include @@ -85,21 +84,32 @@ osg::Geode* createShapes() int main( int argc, char **argv ) { - glutInit( &argc, argv ); + // use an ArgumentParser object to manage the program arguments. + osg::ArgumentParser arguments(&argc,argv); - // create the commandline args. - std::vector commandLine; - for(int i=1;isetCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + + // initialize the viewer. + osgGLUT::Viewer viewer(arguments); - // create the viewer and the model to it. - osgGLUT::Viewer viewer; + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout); + return 1; + } - viewer.setWindowTitle(argv[0]); + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); - - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } osg::Node* node = createShapes(); diff --git a/src/Demos/osgstereoimage/osgstereoimage.cpp b/src/Demos/osgstereoimage/osgstereoimage.cpp index 3574d0986..dd7a19373 100644 --- a/src/Demos/osgstereoimage/osgstereoimage.cpp +++ b/src/Demos/osgstereoimage/osgstereoimage.cpp @@ -9,88 +9,49 @@ #include #include -#include #include - - - -void write_usage(std::ostream& out,const std::string& name) -{ - out << std::endl; - out <<"usage:"<< std::endl; - out <<" "<setCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + + // initialize the viewer. + osgGLUT::Viewer viewer(arguments); + + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) { - write_usage(osg::notify(osg::NOTICE),argv[0]); - return 0; + arguments.getApplicationUsage()->write(std::cout); + return 1; } - // create the commandline args. - std::vector commandLine; - for(int i=1;isetStereo(true); - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); - - // configure the plugin registry from the commandline arguments, and - // eat any parameters that have been matched. - osgDB::readCommandLine(commandLine); - - - if (commandLine.size()<2) + if (arguments.argc()<=2) { osg::notify(osg::NOTICE) << "Please specify two images required for stereo imaging."< commandLine; - for(int i=1;isetCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + + // initialize the viewer. + osgGLUT::Viewer viewer(arguments); - // create the viewer and the model to it. - osgGLUT::Viewer viewer; + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout); + return 1; + } - viewer.setWindowTitle(argv[0]); + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); - - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); - + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } // add model to viewer. viewer.addViewport( createTeapot() ); diff --git a/src/Demos/osgtext/main.cpp b/src/Demos/osgtext/main.cpp index 0e61638a8..006c2cab3 100644 --- a/src/Demos/osgtext/main.cpp +++ b/src/Demos/osgtext/main.cpp @@ -420,28 +420,35 @@ osg::Group* create3DText(const osg::Vec3& center,float radius) int main( int argc, char **argv ) { - // initialize the GLUT - glutInit( &argc, argv ); - - // create the commandline args. - std::vector commandLine; - for(int i=1;isetCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + // initialize the viewer. - osgGLUT::Viewer viewer; - viewer.setWindowTitle(argv[0]); + osgGLUT::Viewer viewer(arguments); - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); - - // configure the plugin registry from the commandline arguments, and - // eat any parameters that have been matched. - osgDB::readCommandLine(commandLine); + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout); + return 1; + } + + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } // load the nodes from the commandline arguments. - osg::ref_ptr rootNode = osgDB::readNodeFiles(commandLine); + osg::ref_ptr rootNode = osgDB::readNodeFiles(arguments); // prepare scene. { diff --git a/src/Demos/osgtexture1D/osgtexture1D.cpp b/src/Demos/osgtexture1D/osgtexture1D.cpp index f6fc28ec5..c6dc4b610 100644 --- a/src/Demos/osgtexture1D/osgtexture1D.cpp +++ b/src/Demos/osgtexture1D/osgtexture1D.cpp @@ -179,34 +179,35 @@ void write_usage(std::ostream& out,const std::string& name) int main( int argc, char **argv ) { - // initialize the GLUT - glutInit( &argc, argv ); + // use an ArgumentParser object to manage the program arguments. + osg::ArgumentParser arguments(&argc,argv); - if (argc<2) + // set up the usage document, in case we need to print out how to use this program. + arguments.getApplicationUsage()->setCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + + // initialize the viewer. + osgGLUT::Viewer viewer(arguments); + + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) { - write_usage(osg::notify(osg::NOTICE),argv[0]); - return 0; + arguments.getApplicationUsage()->write(std::cout); + return 1; } - // create the commandline args. - std::vector commandLine; - for(int i=1;i& commandLine) +ImageList getImagesFromFiles(osg::ArgumentParser& arguments) { ImageList imageList; - for(std::vector::iterator itr=commandLine.begin(); - itr!=commandLine.end(); - ++itr) + for(int i=1;isetCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + + // initialize the viewer. + osgGLUT::Viewer viewer(arguments); + + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) { - write_usage(osg::notify(osg::NOTICE),argv[0]); - return 0; + arguments.getApplicationUsage()->write(std::cout); + return 1; } - // create the commandline args. - std::vector commandLine; - for(int i=1;i commandLine; - for(int i=1;isetCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + // initialize the viewer. - osgGLUT::Viewer viewer; - viewer.setWindowTitle(argv[0]); + osgGLUT::Viewer viewer(arguments); - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); - - // configure the plugin registry from the commandline arguments, and - // eat any parameters that have been matched. - osgDB::readCommandLine(commandLine); + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout); + return 1; + } + + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } // create a model from the images. osg::Node* rootNode = createModel(); diff --git a/src/Demos/osgunittests/osgunittests.cpp b/src/Demos/osgunittests/osgunittests.cpp index e196090aa..299a674d0 100644 --- a/src/Demos/osgunittests/osgunittests.cpp +++ b/src/Demos/osgunittests/osgunittests.cpp @@ -1,14 +1,47 @@ #include +#include +#include - -int main( int /*argc*/, char** /*argv*/ ) +int main( int argc, char** argv ) { -// std::cout<<"***** Qualified Tests ******"<accept( printer ); -// std::cout<setCommandLineUsage(arguments.getProgramName()+" [options]"); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + arguments.getApplicationUsage()->addCommandLineOption("qt","Display qualified tests."); + + + bool printQualifiedTest = false; + while (arguments.read("qt")) printQualifiedTest = true; + + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + std::cout<getCommandLineUsage()<write(std::cout,arguments.getApplicationUsage()->getCommandLineOptions()); + return 1; + } + + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } + + + if (printQualifiedTest) + { + std::cout<<"***** Qualified Tests ******"<accept( printer ); + std::cout<=16"); - - // create the commandline args. - std::vector commandLine; - for(int i=1; isetCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + // initialize the viewer. - osgGLUT::Viewer viewer; - viewer.setWindowTitle(argv[0]); + osgGLUT::Viewer viewer(arguments); - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); - - // configure the plugin registry from the commandline arguments, and - // eat any parameters that have been matched. - osgDB::readCommandLine(commandLine); + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout); + return 1; + } + + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } osg::Group* rootnode = new osg::Group; rootnode->addChild(createSkyBox()); // load the nodes from the commandline arguments. - osg::Node* model = osgDB::readNodeFiles(commandLine); + osg::Node* model = osgDB::readNodeFiles(arguments); if (!model) { const float radius = 1.0f; diff --git a/src/Demos/osgviews/osgviews.cpp b/src/Demos/osgviews/osgviews.cpp index 57ead3374..5eb37fb67 100644 --- a/src/Demos/osgviews/osgviews.cpp +++ b/src/Demos/osgviews/osgviews.cpp @@ -14,68 +14,38 @@ #include -void write_usage(std::ostream& out,const std::string& name) -{ - out << std::endl; - out <<"usage:"<< std::endl; - out <<" "<setCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + + // initialize the viewer. + osgGLUT::Viewer viewer(arguments); + + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) { - write_usage(osg::notify(osg::NOTICE),argv[0]); - return 0; + arguments.getApplicationUsage()->write(std::cout); + return 1; } - // create the commandline args. - std::vector commandLine; - for(int i=1;i -#include -#include #include #include @@ -14,7 +11,6 @@ #include #include - #include struct SortByAverageDistanceFunctor @@ -51,87 +47,42 @@ struct MySortCallback : public osgUtil::RenderBin::SortCallback } }; -void write_usage(std::ostream& out,const std::string& name) -{ - out << std::endl; - out <<"usage:"<< std::endl; - out <<" "<setCommandLineUsage(arguments.getProgramName()+" [options] filename ..."); + arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); + arguments.getApplicationUsage()->addCommandLineOption("-p ","Use specificed animation path file for camera animation"); + + // read the commandline args. std::string pathfile; - - // initialize the GLUT - glutInit( &argc, argv ); - - if (argc<2) - { - write_usage(std::cout,argv[0]); - return 1; - } - - // create the commandline args. - std::vector commandLine; - for(int i=1;i= argc ) { - write_usage( std::cout, argv[0]); - return 1; - } - else - pathfile = std::string(argv[++i]); - } - else - commandLine.push_back(argv[i]); - } + while (arguments.read("-p",pathfile)) {} // initialize the viewer. - osgGLUT::Viewer viewer; - viewer.setWindowTitle(argv[0]); + osgGLUT::Viewer viewer(arguments); - // configure the viewer from the commandline arguments, and eat any - // parameters that have been matched. - viewer.readCommandLine(commandLine); - - // configure the plugin registry from the commandline arguments, and - // eat any parameters that have been matched. - osgDB::readCommandLine(commandLine); + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout); + return 1; + } + + // any option left unread are converted into errors to write out later. + arguments.reportRemainingOptionsAsUnrecognized(); + + // report any errors if they have occured when parsing the program aguments. + if (arguments.errors()) + { + arguments.writeErrorMessages(std::cout); + return 1; + } // load the nodes from the commandline arguments. - osg::Node* rootnode = osgDB::readNodeFiles(commandLine); + osg::Node* rootnode = osgDB::readNodeFiles(arguments); if (!rootnode) { return 1; diff --git a/src/osg/DisplaySettings.cpp b/src/osg/DisplaySettings.cpp index 23ac152c3..11461b759 100644 --- a/src/osg/DisplaySettings.cpp +++ b/src/osg/DisplaySettings.cpp @@ -224,77 +224,6 @@ void DisplaySettings::readEnvironmentalVariables() } } -void DisplaySettings::readCommandLine(std::vector& commandLine) -{ - - bool found = true; - while (found) - { - found = false; - - // check for stereo based options. - std::vector::iterator itr = commandLine.begin(); - for(;itr!=commandLine.end();++itr) - { - if (*itr=="-stereo") break; - } - - if (itr!=commandLine.end()) - { - - _stereo = true; - - std::vector::iterator start = itr; - ++itr; - if (itr!=commandLine.end()) - { - if (*itr=="ANAGLYPHIC") { _stereo = true;_stereoMode = ANAGLYPHIC; ++itr; } - else if (*itr=="QUAD_BUFFER") { _stereo = true;_stereoMode = QUAD_BUFFER; ++itr; } - else if (*itr=="HORIZONTAL_SPLIT") { _stereo = true;_stereoMode = HORIZONTAL_SPLIT; ++itr; } - else if (*itr=="VERTICAL_SPLIT") { _stereo = true;_stereoMode = VERTICAL_SPLIT; ++itr; } - else if (*itr=="LEFT_EYE") { _stereo = true;_stereoMode = LEFT_EYE; ++itr; } - else if (*itr=="RIGHT_EYE") { _stereo = true;_stereoMode = RIGHT_EYE; ++itr; } - else if (*itr=="ON") { _stereo = true; ++itr; } - else if (*itr=="OFF") { _stereo = false; ++itr; } - } - - commandLine.erase(start,itr); - found = true; - } - - // check destination alpha - itr = commandLine.begin(); - for(;itr!=commandLine.end();++itr) - { - if (*itr=="-rgba") break; - } - - if (itr!=commandLine.end()) - { - _RGB = true; - _minimumNumberAlphaBits = 1; - commandLine.erase(itr); - found = true; - } - - - // check stencil buffer - itr = commandLine.begin(); - for(;itr!=commandLine.end();++itr) - { - if (*itr=="-stencil") break; - } - - if (itr!=commandLine.end()) - { - _minimumNumberStencilBits = 1; - commandLine.erase(itr); - found = true; - } - - } -} - void DisplaySettings::readCommandLine(ArgumentParser& arguments) { diff --git a/src/osgDB/Registry.cpp b/src/osgDB/Registry.cpp index 6023a0df9..fb7171a5d 100644 --- a/src/osgDB/Registry.cpp +++ b/src/osgDB/Registry.cpp @@ -71,6 +71,8 @@ Registry::Registry() addFileExtensionAlias("jpeg", "qt"); addFileExtensionAlias("tif", "qt"); addFileExtensionAlias("tiff", "qt"); + addFileExtensionAlias("gif", "qt"); + addFileExtensionAlias("png", "qt"); #else addFileExtensionAlias("jpg", "jpeg"); addFileExtensionAlias("jpe", "jpeg"); @@ -225,79 +227,6 @@ void Registry::initLibraryFilePathList() } -void Registry::readCommandLine(std::vector& commandLine) -{ - - bool found = true; - while (found) - { - found = false; - - // load library option. - std::vector::iterator itr = commandLine.begin(); - for(;itr!=commandLine.end();++itr) - { - if (*itr=="-l") break; - } - - if (itr!=commandLine.end()) - { - std::vector::iterator start = itr; - ++itr; - if (itr!=commandLine.end()) - { - loadLibrary(*itr); - ++itr; - } - commandLine.erase(start,itr); - found = true; - } - - - // load library for extension - itr = commandLine.begin(); - for(;itr!=commandLine.end();++itr) - { - if (*itr=="-e") break; - } - - if (itr!=commandLine.end()) - { - std::vector::iterator start = itr; - ++itr; - if (itr!=commandLine.end()) - { - std::string libName = osgDB::Registry::instance()->createLibraryNameForExt(*itr); - loadLibrary(libName); - ++itr; - } - commandLine.erase(start,itr); - found = true; - } - - // read any option strings that exist. - itr = commandLine.begin(); - for(;itr!=commandLine.end();++itr) - { - if (*itr=="-O") break; - } - - if (itr!=commandLine.end()) - { - std::vector::iterator start = itr; - ++itr; - if (itr!=commandLine.end()) - { - osgDB::Registry::instance()->setOptions(new osgDB::ReaderWriter::Options(*itr)); - ++itr; - } - commandLine.erase(start,itr); - found = true; - } - - } -} - void Registry::readCommandLine(osg::ArgumentParser& arguments) { // report the usage options. diff --git a/src/osgGA/StateSetManipulator.cpp b/src/osgGA/StateSetManipulator.cpp index 34afd6b14..c9d7bf87e 100644 --- a/src/osgGA/StateSetManipulator.cpp +++ b/src/osgGA/StateSetManipulator.cpp @@ -36,9 +36,11 @@ bool StateSetManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& aa) { if(!_drawState.valid()) return false; - if(ea.getEventType()==GUIEventAdapter::KEYDOWN){ + if(ea.getEventType()==GUIEventAdapter::KEYDOWN) + { - switch( ea.getKey() ){ + switch( ea.getKey() ) + { case 'b' : _backface = !_backface; @@ -64,24 +66,24 @@ bool StateSetManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& aa) return true; break; - case 'w' : - { - osg::PolygonMode* polyModeObj = dynamic_cast(_drawState->getAttribute(osg::StateAttribute::POLYGONMODE)); - if (!polyModeObj) + case 'w' : { - polyModeObj = new osg::PolygonMode; - _drawState->setAttribute(polyModeObj); + osg::PolygonMode* polyModeObj = dynamic_cast(_drawState->getAttribute(osg::StateAttribute::POLYGONMODE)); + if (!polyModeObj) + { + polyModeObj = new osg::PolygonMode; + _drawState->setAttribute(polyModeObj); + } + + // cycle through the available modes. + switch(polyModeObj->getMode(osg::PolygonMode::FRONT_AND_BACK)) + { + case osg::PolygonMode::FILL : polyModeObj->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE); break; + case osg::PolygonMode::LINE : polyModeObj->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::POINT); break; + case osg::PolygonMode::POINT : polyModeObj->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::FILL); break; + } } - - // cycle through the available modes. - switch(polyModeObj->getMode(osg::PolygonMode::FRONT_AND_BACK)) - { - case osg::PolygonMode::FILL : polyModeObj->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE); break; - case osg::PolygonMode::LINE : polyModeObj->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::POINT); break; - case osg::PolygonMode::POINT : polyModeObj->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::FILL); break; - } - } - break; + break; } } return false; diff --git a/src/osgGLUT/Viewer.cpp b/src/osgGLUT/Viewer.cpp index 8432f5f55..aaf05fd54 100644 --- a/src/osgGLUT/Viewer.cpp +++ b/src/osgGLUT/Viewer.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -39,6 +40,7 @@ #include #include +#include #include #include @@ -88,6 +90,22 @@ using namespace std; Viewer* Viewer::s_theViewer = 0; Viewer::Viewer() +{ + initialize(); +} + +Viewer::Viewer(osg::ArgumentParser& arguments) +{ + initialize(); + + glutInit( &arguments.argc(), arguments.argv() ); + + setWindowTitle(arguments.getProgramName().c_str()); + readCommandLine(arguments); +} + +void Viewer::initialize() + { s_theViewer = this; @@ -147,24 +165,27 @@ void Viewer::clear() Window::clear(); } - -/** read the command line string list, removing any matched control sequences.*/ -void Viewer::readCommandLine(std::vector& commandLine) +void Viewer::readCommandLine(osg::ArgumentParser& arguments) { - std::vector::iterator itr = commandLine.begin(); - for(;itr!=commandLine.end();++itr) + // report the usage options. + if (arguments.getApplicationUsage()) { - if (*itr=="-f") - { - _fullscreen = true; - break; - } + arguments.getApplicationUsage()->addCommandLineOption("-f","open the application in fullscreen mode"); } - _displaySettings->readCommandLine(commandLine); + + while(arguments.read("-f")) + { + _fullscreen = true; + } + + _displaySettings->readCommandLine(arguments); + + osgDB::readCommandLine(arguments); + } -void -Viewer::toggleFullScreen() + +void Viewer::toggleFullScreen() { _fullscreen = !_fullscreen; if (_fullscreen)