From 0721f0a81860094a33b7ba454a7dbf5819fd4aef Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 19 Dec 2001 10:29:18 +0000 Subject: [PATCH] Updated the demos to support the new commandline handling of stereo and convinience functios for loading libs and files. --- src/Demos/osgcluster/osgcluster.cpp | 4 - src/Demos/osgcube/osgcube.cpp | 13 +++- src/Demos/osgimpostor/osgimpostor.cpp | 104 +++++--------------------- src/Demos/osgreflect/osgreflect.cpp | 99 +++++------------------- src/Demos/osgtexture/osgtexture.cpp | 59 +++++++-------- src/Demos/osgviews/osgviews.cpp | 104 +++++--------------------- src/Demos/sgv/sgv.cpp | 14 ++-- src/osg/VisualsSettings.cpp | 9 ++- src/osgDB/ReadFile.cpp | 2 +- src/osgGLUT/Viewer.cpp | 4 +- 10 files changed, 106 insertions(+), 306 deletions(-) diff --git a/src/Demos/osgcluster/osgcluster.cpp b/src/Demos/osgcluster/osgcluster.cpp index 99fa40b72..9aa11bf49 100644 --- a/src/Demos/osgcluster/osgcluster.cpp +++ b/src/Demos/osgcluster/osgcluster.cpp @@ -286,10 +286,6 @@ osg::Node* getNodeFromFiles(int argc,char **argv, int main( int argc, char **argv ) { -#ifdef USE_MEM_CHECK - mtrace(); -#endif - // initialize the GLUT glutInit( &argc, argv ); diff --git a/src/Demos/osgcube/osgcube.cpp b/src/Demos/osgcube/osgcube.cpp index d8066c19b..51303c92d 100644 --- a/src/Demos/osgcube/osgcube.cpp +++ b/src/Demos/osgcube/osgcube.cpp @@ -164,15 +164,24 @@ int main( int argc, char **argv ) glutInit( &argc, argv ); + // create the commandline args. + std::vector commandLine; + for(int i=1;iaddChild( createCube() ); // move node in a circle at 90 degrees a sec. myTransform->setAppCallback(new MyTransformCallback(myTransform,osg::inDegrees(90.0f))); - // create the viewer and the model to it. - osgGLUT::Viewer viewer; + // add model to viewer. viewer.addViewport( myTransform ); // register trackball maniupulators. diff --git a/src/Demos/osgimpostor/osgimpostor.cpp b/src/Demos/osgimpostor/osgimpostor.cpp index c98faad8c..96326dbf0 100644 --- a/src/Demos/osgimpostor/osgimpostor.cpp +++ b/src/Demos/osgimpostor/osgimpostor.cpp @@ -1,7 +1,3 @@ -#ifdef USE_MEM_CHECK -#include -#endif - #include #include @@ -18,88 +14,9 @@ #include -/* - * Function to read several files (typically one) as specified on the command - * line, and return them in an osg::Node - */ -osg::Node* getNodeFromFiles(int argc,char **argv) -{ - osg::Node *rootnode = new osg::Node; - - int i; - - typedef std::vector NodeList; - NodeList nodeList; - for( i = 1; i < argc; i++ ) - { - - if (argv[i][0]=='-') - { - switch(argv[i][1]) - { - case('l'): - ++i; - if (iloadLibrary(argv[i]); - } - break; - case('e'): - ++i; - if (icreateLibraryNameForExt(argv[i]); - osgDB::Registry::instance()->loadLibrary(libName); - } - break; - } - } else - { - osg::Node *node = osgDB::readNodeFile( argv[i] ); - - if( node != (osg::Node *)0L ) - { - if (node->getName().empty()) node->setName( argv[i] ); - nodeList.push_back(node); - } - } - - } - - if (nodeList.size()==0) - { - osg::notify(osg::WARN) << "No data loaded."<< std::endl; - exit(0); - } - - if (nodeList.size()==1) - { - rootnode = nodeList.front(); - } - else // size >1 - { - osg::Group* group = new osg::Group(); - for(NodeList::iterator itr=nodeList.begin(); - itr!=nodeList.end(); - ++itr) - { - group->addChild(*itr); - } - - rootnode = group; - } - - return rootnode; -} - - int main( int argc, char **argv ) { -#ifdef USE_MEM_CHECK - mtrace(); -#endif - // initialize the GLUT glutInit( &argc, argv ); @@ -123,10 +40,26 @@ int main( int argc, char **argv ) return 0; } + // create the commandline args. + std::vector commandLine; + for(int i=1;i NodeList; - NodeList nodeList; - for( i = 1; i < argc; i++ ) - { - - if (argv[i][0]=='-') - { - switch(argv[i][1]) - { - case('l'): - ++i; - if (iloadLibrary(argv[i]); - } - break; - case('e'): - ++i; - if (icreateLibraryNameForExt(argv[i]); - osgDB::Registry::instance()->loadLibrary(libName); - } - break; - } - } else - { - osg::Node *node = osgDB::readNodeFile( argv[i] ); - - if( node != (osg::Node *)0L ) - { - if (node->getName().empty()) node->setName( argv[i] ); - nodeList.push_back(node); - } - } - - } - - if (nodeList.size()==0) - { - osg::notify(osg::WARN) << "No data loaded."<< std::endl; - exit(0); - } - - if (nodeList.size()==1) - { - rootnode = nodeList.front(); - } - else // size >1 - { - osg::Group* group = new osg::Group(); - for(NodeList::iterator itr=nodeList.begin(); - itr!=nodeList.end(); - ++itr) - { - group->addChild(*itr); - } - - rootnode = group; - } - - return rootnode; -} - osg::StateSet* createMirrorTexturedState(const std::string& filename) { osg::StateSet* dstate = new osg::StateSet; @@ -204,10 +130,26 @@ int main( int argc, char **argv ) return 0; } - - // load a model from file, and add it into the root group node. - osg::Node* loadedModel = getNodeFromFiles( argc, argv); + // create the commandline args. + std::vector commandLine; + for(int i=1;igetBound().center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0f)); diff --git a/src/Demos/osgtexture/osgtexture.cpp b/src/Demos/osgtexture/osgtexture.cpp index 96b90aa53..74148c155 100644 --- a/src/Demos/osgtexture/osgtexture.cpp +++ b/src/Demos/osgtexture/osgtexture.cpp @@ -27,47 +27,25 @@ typedef std::vector< osg::ref_ptr > ImageList; * Function to read several images files (typically one) as specified * on the command line, and return them in an ImageList */ -ImageList getImagesFromFiles(int argc,char **argv) +ImageList getImagesFromFiles(std::vector& commandLine) { ImageList imageList; - int i; - - typedef std::vector NodeList; - NodeList nodeList; - for( i = 1; i < argc; i++ ) + for(std::vector::iterator itr=commandLine.begin(); + itr!=commandLine.end(); + ++itr) { - - if (argv[i][0]=='-') + if ((*itr)[0]!='-') { - switch(argv[i][1]) - { - case('l'): - ++i; - if (iloadLibrary(argv[i]); - } - break; - case('e'): - ++i; - if (icreateLibraryNameForExt(argv[i]); - osgDB::Registry::instance()->loadLibrary(libName); - } - break; - } - } else - { - osg::Image *image = osgDB::readImageFile( argv[i] ); + // not an option so assume string is a filename. + osg::Image *image = osgDB::readImageFile( *itr ); if (image) { imageList.push_back(image); } - } + } } if (imageList.size()==0) @@ -383,8 +361,24 @@ int main( int argc, char **argv ) return 0; } + // create the commandline args. + std::vector commandLine; + for(int i=1;i -#endif #include #include @@ -17,88 +14,10 @@ #include -/* - * Function to read several files (typically one) as specified on the command - * line, and return them in an osg::Node - */ -osg::Node* getNodeFromFiles(int argc,char **argv) -{ - osg::Node *rootnode = new osg::Node; - - int i; - - typedef std::vector NodeList; - NodeList nodeList; - for( i = 1; i < argc; i++ ) - { - - if (argv[i][0]=='-') - { - switch(argv[i][1]) - { - case('l'): - ++i; - if (iloadLibrary(argv[i]); - } - break; - case('e'): - ++i; - if (icreateLibraryNameForExt(argv[i]); - osgDB::Registry::instance()->loadLibrary(libName); - } - break; - } - } else - { - osg::Node *node = osgDB::readNodeFile( argv[i] ); - - if( node != (osg::Node *)0L ) - { - if (node->getName().empty()) node->setName( argv[i] ); - nodeList.push_back(node); - } - } - - } - - if (nodeList.size()==0) - { - osg::notify(osg::WARN) << "No data loaded."<< std::endl; - exit(0); - } - - if (nodeList.size()==1) - { - rootnode = nodeList.front(); - } - else // size >1 - { - osg::Group* group = new osg::Group(); - for(NodeList::iterator itr=nodeList.begin(); - itr!=nodeList.end(); - ++itr) - { - group->addChild(*itr); - } - - rootnode = group; - } - - return rootnode; -} - int main( int argc, char **argv ) { -#ifdef USE_MEM_CHECK - mtrace(); -#endif - // initialize the GLUT glutInit( &argc, argv ); @@ -122,16 +41,27 @@ int main( int argc, char **argv ) return 0; } - osg::Timer timer; - osg::Timer_t before_load = timer.tick(); + // create the commandline args. + std::vector commandLine; + for(int i=1;isetOptions(new osgDB::ReaderWriter::Options("test options")); - // load the nodes from the commandline arguments. osg::Node* rootnode = osgDB::readNodeFiles(commandLine); @@ -70,7 +66,7 @@ int main( int argc, char **argv ) osgUtil::Optimizer optimzer; optimzer.optimize(rootnode); - // add a viewport to the viewer and attah the scene graph. + // add a viewport to the viewer and attach the scene graph. viewer.addViewport( rootnode ); // register trackball, flight and drive. diff --git a/src/osg/VisualsSettings.cpp b/src/osg/VisualsSettings.cpp index cc8f4f2b2..369c3d047 100644 --- a/src/osg/VisualsSettings.cpp +++ b/src/osg/VisualsSettings.cpp @@ -104,6 +104,11 @@ void VisualsSettings::readEnvironmentalVariables() { _eyeSeperation = atof(ptr); } + + if( (ptr = getenv("OSG_SCREEN_DISTANCE")) ) + { + _screenDistance = atof(ptr); + } } void VisualsSettings::readCommandLine(std::vector& commandLine) @@ -131,9 +136,9 @@ void VisualsSettings::readCommandLine(std::vector& commandLine) if (itr!=commandLine.end()) { if (*itr=="ANAGLYPHIC") { _stereo = true;_stereoMode = ANAGLYPHIC; ++itr; } - else if (*itr=="QUAD_STEREO") { _stereo = true;_stereoMode = QUAD_BUFFER; ++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=="VERITCAL_SPLIT") { _stereo = true;_stereoMode = VERTICAL_SPLIT; ++itr; } + else if (*itr=="VERTICAL_SPLIT") { _stereo = true;_stereoMode = VERTICAL_SPLIT; ++itr; } else if (*itr=="ON") { _stereo = true; ++itr; } else if (*itr=="OFF") { _stereo = false; ++itr; } } diff --git a/src/osgDB/ReadFile.cpp b/src/osgDB/ReadFile.cpp index ff8efa0b1..f7753643b 100644 --- a/src/osgDB/ReadFile.cpp +++ b/src/osgDB/ReadFile.cpp @@ -41,7 +41,7 @@ Node* osgDB::readNodeFiles(std::vector& commandLine) typedef std::vector NodeList; NodeList nodeList; - // note currently doesn't delete the loaded files yet... + // note currently doesn't delete the loaded file entries from the command line yet... for(std::vector::iterator itr=commandLine.begin(); itr!=commandLine.end(); diff --git a/src/osgGLUT/Viewer.cpp b/src/osgGLUT/Viewer.cpp index ec4d53528..b6c88d903 100644 --- a/src/osgGLUT/Viewer.cpp +++ b/src/osgGLUT/Viewer.cpp @@ -239,9 +239,7 @@ bool Viewer::open() Node* node = itr->sceneView->getSceneData(); if (node) node->accept(vrv); } -#ifdef _DEBUG - _visualsSettings->setMinimumNumStencilBits(8); //gwm 12.8.01 to force stencils available for DC test -#endif + // set up each render stage to clear the appropriate buffers. GLbitfield clear_mask=0; if (_visualsSettings->getRGB()) clear_mask |= GL_COLOR_BUFFER_BIT;