|
如题:
在程序中我用一个主相机,两个从相机来渲染同一个场景,在程序中用CEGUI做的界面,可是刚开始运行的时候,界面就显示不出来了,不知道用主相机和从相机来渲染同一个场景的时候,CEGUI界面应该怎么处理呢?
一些代码:
osg::Camera* createCamera(int x, int y, int w, int h)
{
osg::ref_ptr<osg::GraphicsContext::Traits> trait = new osg::GraphicsContext::Traits();
trait->x = x;
trait->y = y;
trait->width = w;
trait->height = h;
trait->windowDecoration = false;
trait->doubleBuffer = true;
double fov;
double ratio;
double nearPlane;
double farPlane;
double newAspectRaito = double(trait->width)/double(trait->height);
osg:isplaySettings *ds = osg::DisplaySettings::instance();
trait->alpha = ds->getMinimumNumAlphaBits();
trait->stencil = ds->getMinimumNumStencilBits();
trait->sampleBuffers = ds->getMultiSamples();
trait->samples = ds->getNumMultiSamples();
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(trait.get());
osg::ref_ptr<osg::Camera> camera = new osg::Camera();
camera->setGraphicsContext(gc.get());
camera->setViewport(new osg::Viewport(0,0,w,h));
//设置视景参数,将yz平面视野角度设为50°
//换取对称视景个参数并显示,每个屏幕都有对应的ratio,所以必须先get再set
camera->getProjectionMatrixAsPerspective( fov,ratio,nearPlane,farPlane);
camera->setProjectionMatrixAsPerspective(50.0f, newAspectRaito, 1, 1000.0);
camera->setNearFarRatio(0.000003f);
camera->setClearColor(osg::Vec4(0.0,0.0,0.0,0.5));
return camera.release();
}
main函数相关代码:
//得到窗口的图形环境
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
if (!wsi)
{
osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
}
unsigned int tileWidth, tileHeight;
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), tileWidth ,tileHeight);
//初始化主相机
osg::ref_ptr<osg::GraphicsContext::Traits> mastertrait = new osg::GraphicsContext::Traits();
mastertrait->x = tileWidth/3+5;
mastertrait->y = 0;
mastertrait->width = tileWidth/3;
mastertrait->height = tileHeight;
mastertrait->windowDecoration = false;
mastertrait->doubleBuffer = true;
osg::DisplaySettings *ds = osg::DisplaySettings::instance();
mastertrait->alpha = ds->getMinimumNumAlphaBits();
mastertrait->stencil = ds->getMinimumNumStencilBits();
mastertrait->sampleBuffers = ds->getMultiSamples();
mastertrait->samples = ds->getNumMultiSamples();
osg::ref_ptr<osg::GraphicsContext> mastergc = osg::GraphicsContext::createGraphicsContext(mastertrait.get());
osg::ref_ptr<osg::Camera> masterCamera = new osg::Camera();
masterCamera = viewer->getCamera();
masterCamera->setGraphicsContext(mastergc.get());
masterCamera->setViewport(new osg::Viewport(0,0,mastertrait->width,mastertrait->height));
//添加从相机
viewer->addSlave(createCamera(0,0,tileWidth/3,tileHeight),osg::Matrixd::translate(2.0,0.0,0.0),osg::Matrixd());
viewer->addSlave(createCamera(2*tileWidth/3,0,tileWidth/3,tileHeight),osg::Matrixd::translate(-2.0,0.0,0.0),osg::Matrixd());
osg::ref_ptr<osgViewer::GraphicsWindowWin32> gcwin32=dynamic_cast<osgViewer::GraphicsWindowWin32*>(masterCamera->getGraphicsContext());
//UI
masterCamera->getGraphicsContext()->makeCurrent(); //创建背景图片
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
osg::ref_ptr<CEGUIDrawable> cd = new CEGUIDrawable(sceneMgr,KeySoundNode,viewer,ClickSoundNode,gcwin32/*,printer.get()*/);//界面节点
geode->addDrawable(cd.get()); |
|