|
刚接触OSG不久,最近疑惑一个问题,就是自己创建了一个摄像机,设置到场景中,然后再调用viewer的run函数来进行渲染,结果窗口一直不显示,如果不添加自己创建的摄像机,就可以正常显示,不知道这是什么原因,代码:
//创建摄像机
osg::Camera* camera = createCamera( 50, 50, 640, 480 );
m_viewer.setCamera( camera );
//添加数据到场景
m_viewer.setSceneData(m_pRoot);
m_viewer.run();
//创建摄像机
osg::Camera* ViewerWidget::createCamera(int x, int y, int w, int h)
{
osg:isplaySettings* ds = osg::DisplaySettings::instance().get();
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->windowDecoration = false;
traits->x = x;
traits->y = y;
traits->width = w;
traits->height = h;
traits->doubleBuffer = true;
traits->samples = 8;
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setGraphicsContext( new osgQt::GraphicsWindowQt(traits.get()) );
camera->setClearColor( osg::Vec4(0.2, 0.2, 0.6, 1.0) );
camera->setViewport( new osg::Viewport(0, 0, traits->width, traits->height) );
camera->setProjectionMatrixAsPerspective( 30.0f, static_cast<double>(traits->width) /
static_cast<double>(traits->height), 1.0f, 10000.0f );
return camera.release();
} |
|