|
小弟最近在看《Open Scence Graph一书 三维视景仿真技术开发详解》在看到后视图创建的时候发现后视图一直无法显示。这是我的代码,请大牛们华丽的找出问题。
- #ifdef _DEBUG
- #pragma comment(lib,"osgViewerd.lib")
- #pragma comment(lib,"OpenThreadsd.lib")
- #pragma comment(lib,"osgd.lib")
- #pragma comment(lib,"osgDBd.lib")
- #else
- #pragma comment(lib,"osgViewer.lib")
- #pragma comment(lib,"OpenThreads.lib")
- #pragma comment(lib,"osg.lib")
- #pragma comment(lib,"osgDB.lib")
- #endif
- #include <osgViewer/Viewer>
- #include <osgDB/ReadFile>
- #include <osg/Camera>
- #include <osg/GraphicsContext>
- #include <osg/Texture2D>
- #include <osg/ShapeDrawable>
- #include <iostream>
- #include <osg/StateSet>
- #include <osg/Geode>
- #include <osg/ShapeDrawable>
- #include <osg/Material>
- #include <osg/Image>
- #include <osg/Texture2D>
- osg::Geode * CreateScene()
- {
- osg::Geode * gmode= new osg::Geode;
- gmode->addDrawable(new osg::ShapeDrawable(new osg::Box(osg::Vec3(0,0.0,0.0),10.0,30.0,150.0)));
- gmode->addDrawable(new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.0,0,0.0),150.0,10.0,10.0)));
-
- return gmode;
- }
- void CreateCamera(osgViewer::Viewer * myViewer)
- {
- if (!myViewer)
- {
- return;
- }
- osg::GraphicsContext::WindowingSystemInterface *wsi= osg::GraphicsContext::getWindowingSystemInterface();
- if (!wsi)
- {
- return;
- }
- unsigned int width,height;
- wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0),width,height);
- osg::ref_ptr<osg::GraphicsContext::Traits> traits= new osg::GraphicsContext::Traits ;
- traits->x=0;
- traits->y=0;
- traits->width=width;
- traits->height=height;
- traits->windowDecoration=false;
- traits->doubleBuffer=true;
- traits->sharedContext=0;
- osg::ref_ptr<osg::GraphicsContext> gc= osg::GraphicsContext::createGraphicsContext(traits);
- if (!gc)
- {
- return;
- }
- osg::ref_ptr<osg::Camera> master= new osg::Camera;
- master->setGraphicsContext(gc);
- master->setViewport(0,0,width,height);
- myViewer->addSlave(master);
- osg::ref_ptr<osg::Camera> leftCam= new osg::Camera;
- leftCam->setViewport(0,0,width/2,height/2);
- leftCam->setGraphicsContext(gc);
- leftCam->setRenderOrder(osg::Camera::POST_RENDER);
- myViewer->addSlave(leftCam,osg::Matrix::scale(0.5,0.5,0.5),osg::Matrix::rotate(osg::DegreesToRadians(180.0),1.0,0.0,0.0),true);
- osg::ref_ptr<osg::Group> root= new osg::Group;
- root->addChild(CreateScene());
- myViewer->setSceneData(root);
- return;
- }
- int main()
- {
- osg::ref_ptr<osgViewer::Viewer> myViewer= new osgViewer::Viewer;
- CreateCamera(myViewer);
- myViewer->run();
- return 0;
- }
复制代码 |
|