|
写了一段很简单的代码,但是有一个疑问,查了Help也没搞清楚
代码如下:- #include <Windows.h>
- #include <osg/Group>
- #include <osg/Geometry>
- #include <osg/Shape>
- #include <osg/ShapeDrawable>
- #include <osgViewer/Viewer>
- #include <osgUtil/Optimizer>
- //场景图形根节点
- osg::Group *root = NULL;
- void CreateOSG()
- {
- root = new osg::Group();
- osg::Box *box = new osg::Box(osg::Vec3(2.0f, 0.0f, 0.0f), 2.0f);
- osg::Geode *geode = new osg::Geode();
- geode->addDrawable(new osg::ShapeDrawable(box));
- root->addChild(geode);
- osgUtil::Optimizer optimizer;
- optimizer.optimize(root);
- }
- int main ()
- {
- osgViewer::Viewer *viewer = new osgViewer::Viewer();
- CreateOSG();
- viewer->setSceneData(root);
- while (!viewer->done())
- {
- viewer->frame();
- }
-
- return 0;
- }
复制代码 上述代码无法正常显示正方体
但是将- while (!viewer->done())
- {
- viewer->frame();
- }
复制代码 换成- viewer->realize();
- viewer->run();
复制代码 就没有问题了
这个是什么原因呢? |
|