From fa70860427e04c80726572453714c67973f227e2 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 31 Jan 2003 00:44:56 +0000 Subject: [PATCH] Port of osghangglide to use osg producer. Default build still uses GLUT. --- src/Demos/osghangglide/Makefile | 5 + src/Demos/osghangglide/osghangglide.cpp | 194 ++++++++++++++----- src/Demos/osgproducer/osgproducer_viewer.cpp | 9 +- 3 files changed, 156 insertions(+), 52 deletions(-) diff --git a/src/Demos/osghangglide/Makefile b/src/Demos/osghangglide/Makefile index 62930ea68..82bb0cc63 100644 --- a/src/Demos/osghangglide/Makefile +++ b/src/Demos/osghangglide/Makefile @@ -19,6 +19,7 @@ HEADERFILES = \ terrain_texcoords.h\ LIBS += $(OSG_LIBS) $(GLUT_LIB) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) +#LIBS += -losgProducer -l Producer $(OSG_LIBS) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) INSTFILES = \ $(CXXFILES)\ @@ -27,4 +28,8 @@ INSTFILES = \ EXEC = osghangglide +CXXFLAGS += -DUSE_GLUT +#CXXFLAGS += $(PRODUCER_INCLUDE_DIR) +#LDFLAGS += $(PRODUCER_LIB_DIR) + include $(TOPDIR)/Make/makerules diff --git a/src/Demos/osghangglide/osghangglide.cpp b/src/Demos/osghangglide/osghangglide.cpp index 4b2ea32bd..8483d7118 100644 --- a/src/Demos/osghangglide/osghangglide.cpp +++ b/src/Demos/osghangglide/osghangglide.cpp @@ -10,8 +10,7 @@ #include #include -#include -#include +#include #include "GliderManipulator.h" @@ -52,6 +51,58 @@ struct MoveEarthySkyWithEyePointCallback : public osg::Transform::ComputeTransfo } }; +osg::Group* createModel() +{ + // no database loaded so automatically create Ed Levin Park.. + osg::Group* group = new osg::Group; + + // the base and sky subgraphs go to set the earth sky of the + // model and clear the color and depth buffer for us, by using + // osg::Depth, and setting their bin numbers to less than 0, + // to force them to draw before the rest of the scene. + + osg::ClearNode* clearNode = new osg::ClearNode; + clearNode->setRequiresClear(false); // we've got base and sky to do it. + + // use a transform to make the sky and base around with the eye point. + osg::Transform* transform = new osg::Transform; + + // transform's value isn't knowm until in the cull traversal so its bounding + // volume is can't be determined, therefore culling will be invalid, + // so switch it off, this cause all our paresnts to switch culling + // off as well. But don't worry culling will be back on once underneath + // this node or any other branch above this transform. + transform->setCullingActive(false); + + // set the compute transform callback to do all the work of + // determining the transform according to the current eye point. + transform->setComputeTransformCallback(new MoveEarthySkyWithEyePointCallback); + + // add the sky and base layer. + transform->addChild(makeSky()); // bin number -2 so drawn first. + transform->addChild(makeBase()); // bin number -1 so draw second. + + // add the transform to the earth sky. + clearNode->addChild(transform); + + // add to earth sky to the scene. + group->addChild(clearNode); + + // the rest of the scene drawn after the base and sky above. + group->addChild(makeTrees()); // will drop into a transparent, depth sorted bin (1) + group->addChild(makeTerrain()); // will drop into default bin - state sorted 0 + group->addChild(makeTank()); // will drop into default bin - state sorted 0 + // add the following in the future... + // makeGliders + // makeClouds + + return group; +} + +#ifdef USE_GLUT + +#include +#include int main( int argc, char **argv ) { @@ -75,53 +126,7 @@ int main( int argc, char **argv ) // load the nodes from the commandline arguments. osg::Node* rootnode = osgDB::readNodeFiles(commandLine); - if (!rootnode) - { - // no database loaded so automatically create Ed Levin Park.. - osg::Group* group = new osg::Group; - rootnode = group; - - // the base and sky subgraphs go to set the earth sky of the - // model and clear the color and depth buffer for us, by using - // osg::Depth, and setting their bin numbers to less than 0, - // to force them to draw before the rest of the scene. - - osg::ClearNode* clearNode = new osg::ClearNode; - clearNode->setRequiresClear(false); // we've got base and sky to do it. - - // use a transform to make the sky and base around with the eye point. - osg::Transform* transform = new osg::Transform; - - // transform's value isn't knowm until in the cull traversal so its bounding - // volume is can't be determined, therefore culling will be invalid, - // so switch it off, this cause all our paresnts to switch culling - // off as well. But don't worry culling will be back on once underneath - // this node or any other branch above this transform. - transform->setCullingActive(false); - - // set the compute transform callback to do all the work of - // determining the transform according to the current eye point. - transform->setComputeTransformCallback(new MoveEarthySkyWithEyePointCallback); - - // add the sky and base layer. - transform->addChild(makeSky()); // bin number -2 so drawn first. - transform->addChild(makeBase()); // bin number -1 so draw second. - - // add the transform to the earth sky. - clearNode->addChild(transform); - - // add to earth sky to the scene. - group->addChild(clearNode); - - // the rest of the scene drawn after the base and sky above. - group->addChild(makeTrees()); // will drop into a transparent, depth sorted bin (1) - group->addChild(makeTerrain()); // will drop into default bin - state sorted 0 - group->addChild(makeTank()); // will drop into default bin - state sorted 0 - // add the following in the future... - // makeGliders - // makeClouds - - } + if (!rootnode) rootnode = createModel(); viewer.addViewport( rootnode ); @@ -136,3 +141,94 @@ int main( int argc, char **argv ) return 0; } + +#else + +#include + +int main( int argc, char **argv ) +{ + // create the commandline args. + std::string pathfile; + std::string configfile; + std::vector commandLine; + for(int i=1;i= argc ) { + std::cout << "path argument required for -p option."<= argc ) { + std::cout << "path argument required for -c option."<readCommandLine(commandLine); + osgDB::readCommandLine(commandLine); + + osgProducer::Viewer* viewer = 0; + if (!configfile.empty()) viewer = new osgProducer::Viewer(configfile); + else viewer = new osgProducer::Viewer; + + // 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); + if (!rootnode) rootnode = createModel(); + + + // set the scene to render + viewer->setSceneData(rootnode); + + // set up the value with sensible defaults. + viewer->setUpViewer(); + + unsigned int pos = viewer->addCameraManipulator(new GliderManipulator()); + viewer->selectCameraManipulator(pos); + + if( !pathfile.empty() ) { + osg::ref_ptr apm = new osgGA::AnimationPathManipulator(pathfile); + if( apm.valid() && apm->valid() ) + { + unsigned int num = viewer->addCameraManipulator(apm.get()); + viewer->selectCameraManipulator(num); + } + } + + + // set up the stack size + viewer->setStackSize( 20* 1024 * 1024); + + // create the windows and run the threads. + viewer->realize(Producer::CameraGroup::ThreadPerCamera); + + while( !viewer->done() ) + { + // wait for all cull and draw threads to complete. + viewer->sync(); + + // update the scene by traversing it with the the update visitor which will + // call all node update callbacks and animations. + viewer->update(); + + // fire off the cull and draw traversals of the scene. + viewer->frame(); + + } + return 0; +} + +#endif diff --git a/src/Demos/osgproducer/osgproducer_viewer.cpp b/src/Demos/osgproducer/osgproducer_viewer.cpp index 199f05fb1..03ad4abf1 100644 --- a/src/Demos/osgproducer/osgproducer_viewer.cpp +++ b/src/Demos/osgproducer/osgproducer_viewer.cpp @@ -15,8 +15,6 @@ int main( int argc, char **argv ) { - // create the camera group. - // create the commandline args. std::string pathfile; std::string configfile; @@ -43,11 +41,16 @@ int main( int argc, char **argv ) commandLine.push_back(argv[i]); } + osg::DisplaySettings::instance()->readCommandLine(commandLine); + osgDB::readCommandLine(commandLine); + osgProducer::Viewer* viewer = 0; if (!configfile.empty()) viewer = new osgProducer::Viewer(configfile); else viewer = new osgProducer::Viewer; - osg::DisplaySettings::instance()->readCommandLine(commandLine); + + // configure the plugin registry from the commandline arguments, and + // eat any parameters that have been matched. osgDB::readCommandLine(commandLine);