Updated the demos to support the new commandline handling of stereo and

convinience functios for loading libs and files.
This commit is contained in:
Robert Osfield 2001-12-19 10:29:18 +00:00
parent 3c1c0f015e
commit 0721f0a818
10 changed files with 106 additions and 306 deletions

View File

@ -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 );

View File

@ -164,15 +164,24 @@ int main( int argc, char **argv )
glutInit( &argc, argv );
// create the commandline args.
std::vector<std::string> commandLine;
for(int i=1;i<argc;++i) commandLine.push_back(argv[i]);
// create the viewer and the model to it.
osgGLUT::Viewer viewer;
// configure the viewer from the commandline arguments, and eat any
// parameters that have been matched.
viewer.readCommandLine(commandLine);
osg::Transform* myTransform = new osg::Transform();
myTransform->addChild( 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.

View File

@ -1,7 +1,3 @@
#ifdef USE_MEM_CHECK
#include <mcheck.h>
#endif
#include <osg/Impostor>
#include <osg/Notify>
@ -18,88 +14,9 @@
#include <osg/Quat>
/*
* 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<osg::Node*> NodeList;
NodeList nodeList;
for( i = 1; i < argc; i++ )
{
if (argv[i][0]=='-')
{
switch(argv[i][1])
{
case('l'):
++i;
if (i<argc)
{
osgDB::Registry::instance()->loadLibrary(argv[i]);
}
break;
case('e'):
++i;
if (i<argc)
{
std::string libName = osgDB::Registry::instance()->createLibraryNameForExt(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<std::string> commandLine;
for(int i=1;i<argc;++i) commandLine.push_back(argv[i]);
osg::Timer timer;
osg::Timer_t before_load = timer.tick();
osg::Node* model = getNodeFromFiles( argc, argv);
// initialize the viewer.
osgGLUT::Viewer viewer;
// 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* model = osgDB::readNodeFiles(commandLine);
// the osgUtil::InsertImpostorsVisitor used lower down to insert impostors
@ -182,8 +115,7 @@ int main( int argc, char **argv )
osg::Timer_t after_load = timer.tick();
std::cout << "Time for load = "<<timer.delta_s(before_load,after_load)<<" seconds"<< std::endl;
// initialize the viewer.
osgGLUT::Viewer viewer;
// add model to viewer.
viewer.addViewport( rootnode );
// register trackball, flight and drive.

View File

@ -42,80 +42,6 @@
// we apply them.
/*
* 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<osg::Node*> NodeList;
NodeList nodeList;
for( i = 1; i < argc; i++ )
{
if (argv[i][0]=='-')
{
switch(argv[i][1])
{
case('l'):
++i;
if (i<argc)
{
osgDB::Registry::instance()->loadLibrary(argv[i]);
}
break;
case('e'):
++i;
if (i<argc)
{
std::string libName = osgDB::Registry::instance()->createLibraryNameForExt(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<std::string> commandLine;
for(int i=1;i<argc;++i) commandLine.push_back(argv[i]);
// initialize the viewer.
osgGLUT::Viewer viewer;
// 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);
if (!loadedModel)
{
write_usage();
@ -410,8 +352,7 @@ int main( int argc, char **argv )
}
// initialize the viewer.
osgGLUT::Viewer viewer;
// add model to the viewer.
viewer.addViewport( rootNode );
osg::NodeCallback* nc = new osgUtil::TransformCallback(loadedModelTransform->getBound().center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0f));

View File

@ -27,47 +27,25 @@ typedef std::vector< osg::ref_ptr<osg::Image> > 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<std::string>& commandLine)
{
ImageList imageList;
int i;
typedef std::vector<osg::Node*> NodeList;
NodeList nodeList;
for( i = 1; i < argc; i++ )
for(std::vector<std::string>::iterator itr=commandLine.begin();
itr!=commandLine.end();
++itr)
{
if (argv[i][0]=='-')
if ((*itr)[0]!='-')
{
switch(argv[i][1])
{
case('l'):
++i;
if (i<argc)
{
osgDB::Registry::instance()->loadLibrary(argv[i]);
}
break;
case('e'):
++i;
if (i<argc)
{
std::string libName = osgDB::Registry::instance()->createLibraryNameForExt(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<std::string> commandLine;
for(int i=1;i<argc;++i) commandLine.push_back(argv[i]);
// initialize the viewer.
osgGLUT::Viewer viewer;
// 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 images specified on command line
ImageList imageList = getImagesFromFiles(argc,argv);
ImageList imageList = getImagesFromFiles(commandLine);
if (!imageList.empty())
@ -393,8 +387,7 @@ int main( int argc, char **argv )
// create a model from the images.
osg::Node* rootNode = createModelFromImages(imageList);
// initialize the viewer.
osgGLUT::Viewer viewer;
// add model to viewer.
viewer.addViewport( rootNode );
// register trackball, flight and drive.

View File

@ -1,6 +1,3 @@
#ifdef USE_MEM_CHECK
#include <mcheck.h>
#endif
#include <osg/Group>
#include <osg/Notify>
@ -17,88 +14,10 @@
#include <osg/Quat>
/*
* 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<osg::Node*> NodeList;
NodeList nodeList;
for( i = 1; i < argc; i++ )
{
if (argv[i][0]=='-')
{
switch(argv[i][1])
{
case('l'):
++i;
if (i<argc)
{
osgDB::Registry::instance()->loadLibrary(argv[i]);
}
break;
case('e'):
++i;
if (i<argc)
{
std::string libName = osgDB::Registry::instance()->createLibraryNameForExt(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<std::string> commandLine;
for(int i=1;i<argc;++i) commandLine.push_back(argv[i]);
osg::Node* rootnode = getNodeFromFiles( argc, argv);
osg::Timer_t after_load = timer.tick();
std::cout << "Time for load = "<<timer.delta_s(before_load,after_load)<<" seconds"<< std::endl;
// initialize the viewer.
osgGLUT::Viewer viewer;
// 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);
// create the vewiports
viewer.addViewport( rootnode,0.0,0.0,0.5,0.5);
viewer.addViewport( rootnode,0.5,0.0,0.5,0.5);
viewer.addViewport( rootnode,0.0,0.5,1.0,0.5);

View File

@ -51,18 +51,14 @@ int main( int argc, char **argv )
// initialize the viewer.
osgGLUT::Viewer viewer;
// configure the viewer from the commandline arguments.
// configure the viewer from the commandline arguments, and eat any
// parameters that have been matched.
viewer.readCommandLine(commandLine);
// configure the plguin registry from the commandline arguments.
// configure the plugin registry from the commandline arguments, and
// eat any parameters that have been matched.
osgDB::readCommandLine(commandLine);
// comment out right now, but the following allows users to pass option data to
// the ReaderWriter plugins. By default the options are set to NULL. The basic
// osgDB::ReaderWriter::Options stucture has just a string, but this can be
// subclassed to extend it to handle any options that a user desires.
// osgDB::Registry::instance()->setOptions(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.

View File

@ -104,6 +104,11 @@ void VisualsSettings::readEnvironmentalVariables()
{
_eyeSeperation = atof(ptr);
}
if( (ptr = getenv("OSG_SCREEN_DISTANCE")) )
{
_screenDistance = atof(ptr);
}
}
void VisualsSettings::readCommandLine(std::vector<std::string>& commandLine)
@ -131,9 +136,9 @@ void VisualsSettings::readCommandLine(std::vector<std::string>& 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; }
}

View File

@ -41,7 +41,7 @@ Node* osgDB::readNodeFiles(std::vector<std::string>& commandLine)
typedef std::vector<osg::Node*> 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<std::string>::iterator itr=commandLine.begin();
itr!=commandLine.end();

View File

@ -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;