OSG简单测试框架
#include <osgDB/ReadFile> #include <osgDB/FileUtils> #include <osg/ArgumentParser> #include <osgViewer/Viewer> #include <osgViewer/ViewerEventHandlers> #include <osgGA/StateSetManipulator> #ifdef _DEBUG #pragma comment(lib, "osgd.lib") #pragma comment(lib, "osgDBd.lib") #pragma comment(lib, "osgViewerd.lib") #pragma comment(lib, "osgGAd.lib") #else #pragma comment(lib, "osg.lib") #pragma comment(lib, "osgDB.lib") #pragma comment(lib, "osgViewer.lib") #pragma comment(lib, "osgGA.lib") #endif // DEBUG int main(int argc, char **argv) { // 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()->setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName() + " is an OpenSceneGraph example that shows how to use the accumulation buffer to achieve a simple motion blur effect."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName() + " data path. e.g. D:\\OSG\\Data. 如果此参数为空,则读取当前文件目录下的Data目录"); arguments.getApplicationUsage()->addCommandLineOption("-h or --help", "Display this information"); //arguments.getApplicationUsage()->addCommandLineOption("-arg1", "arg1"); // construct the viewer. osgViewer::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; } double arg1 = 0.25; arguments.read("-arg1", arg1); osg::ref_ptr<osg::Group> root = new osg::Group; /*// read the scene from the list of file specified command line args. osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); // if not loaded assume no arguments passed in, try use default mode instead. if (!loadedModel) loadedModel = osgDB::readNodeFile("cow.osg"); // if no model has been successfully loaded report failure. if (!loadedModel) { std::cout << arguments.getApplicationName() << ": No data loaded" << std::endl; return 1; } root->addChild(loadedModel); */ std::string dataPath = "."; if (argc>1) { std::cout << argv[1]; dataPath = argv[1]; } dataPath += "\\Data\\"; osgDB::DirectoryContents dirNames = osgDB::getDirectoryContents(dataPath); for each (std::string dir in dirNames) { if (dir.find(".") != std::string::npos) continue; std::string osgbFile = dataPath + dir + "\\"+ dir+".osgb"; root->addChild(osgDB::readNodeFile(osgbFile)); } // pass the loaded scene graph to the viewer. viewer.setSceneData(root.get()); // add the state manipulator viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet())); // add the thread model handler viewer.addEventHandler(new osgViewer::ThreadingHandler); // add the window size toggle handler viewer.addEventHandler(new osgViewer::WindowSizeHandler); // add the stats handler viewer.addEventHandler(new osgViewer::StatsHandler); // add the help handler viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage())); // add the record camera path handler viewer.addEventHandler(new osgViewer::RecordCameraPathHandler); // add the LOD Scale handler viewer.addEventHandler(new osgViewer::LODScaleHandler); // add the screen capture handler viewer.addEventHandler(new osgViewer::ScreenCaptureHandler); // create the windows and run the threads. viewer.realize(); return viewer.run(); }