|
利用osg例子中提供的方法在mfc的单文档下渲染了一个场景,场景的组织结构是一个复合视图关联了两个子视图,一个视图关联了一个camera,每个相机关联了一个图形上下文,可是mfc只能创建一个图形上下文,或者一个图形上下文只能关联到一个相机上,否则就会出错 ,不知道是什么原因,望得到指教,谢谢!
// 创建图形上下文特征对象
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
// Init the Windata Variable that holds the handle for the Window to display OSG in.
osg::ref_ptr<osg::Referenced> windata = new osgViewer::GraphicsWindowWin32::WindowData(m_hWnd);
// 设置图形上下文特征
traits->x = 0;
traits->y = 0;
traits->width = rect.right - rect.left;
traits->height = rect.bottom - rect.top;
traits->windowDecoration = false;
traits->doubleBuffer = true;
traits->sharedContext = 0;
traits->setInheritedWindowPixelFormat = true;
traits->inheritedWindowData = windata;
// 创建图形上下文
osg::GraphicsContext* earthgc = osg::GraphicsContext::createGraphicsContext(traits.get());
// Init a new Camera (Master for this View)
osg::ref_ptr<osg::Camera> earthcamera = m_earthViewer->getCamera();
earthcamera->setGraphicsContext(earthgc); //设置和下面的相机设置冲突,不知道是什么原因,望指教
/**************************************************************************/
osg::ref_ptr<osg::Camera> communitycamera = m_communityViewer->getCamera();
//设置背景色为黑色
communitycamera->setClearColor(osg::Vec4f(0.5,0.5,0.0,1.0));
// Assign Graphics Context to the Camera
communitycamera->setGraphicsContext(earthgc);设置和上面的相机设置冲突,不知道是什么原因,望指教 |
|