做如下一段代码;
#include <Windows.h>
#include <osgViewer/Viewer>#include <osg/Node>
#include <osg/Geode>
#include <osg/Group>#include <osgDB/ReadFile>
#include <osgDB/WriteFile>#include <osgUtil/Optimizer>int a;int main()
{osgViewer::Viewer* viewer = new osgViewer::Viewer();osg::Group* root = new osg::Group();osg::Node* node = new osg::Node();node = osgDB::readNodeFile("tree.osg");root->addChild(node);osgUtil::Optimizer optimizer;optimizer.optimize(root);viewer->setSceneData(root);viewer->realize();viewer->run();std::cin >> a;if (a == 1){root->removeChild(node);osg::Node* node2 = new osg::Node();node2 = osgDB::readNodeFile("boxman.osg");root->addChild(node2);}return 0;
}
模型窗口显示以后,不会执行 viewer->run() 后面的语句;只有在关闭模型窗口后,才会执行 viewer->run() 后面的语