|
本帖最后由 1162810317 于 2013-10-5 20:13 编辑
mfc框架的程序,加了mViewer->addEventHandler(new osgViewer::StatsHandler);但按“s”键后程序就奔溃。键盘控制器和其他的控制器可以正常工作如keyswitchManipulator->addMatrixManipulator( '1', "Trackball", trackball.get());请教大神们可能是什么原因!此外就是一旦把键盘操作器去掉,就没办法显示场景,变成黑的。注释掉mViewer->setCameraManipulator(keyswitchManipulator.get());后场景变黑。- // 局部变量存放窗口矩形
- RECT rect;
- // 创建一个viewer
- mViewer = new osgViewer::Viewer();
- // 加入一个statshandler
-
- mViewer->addEventHandler(new osgViewer::StatsHandler);
-
- // 得到当前窗口矩形
- ::GetWindowRect(m_hWnd, &rect);
- // 初始化图形描述什么东西,反正就是那么回事
- osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
- // 初始化窗口变量,为OSG所用
- 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* gc = osg::GraphicsContext::createGraphicsContext(traits.get());
- // 初始化一个相机
- osg::ref_ptr<osg::Camera> camera = new osg::Camera;
- // 绑
- camera->setGraphicsContext(gc);
- camera->setClearColor( osg::Vec4(0.39, 0.39, 0.39, 1.0) );
- GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
- camera->setDrawBuffer(buffer);
- camera->setReadBuffer(buffer);
- camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- //相机视口设置
- camera->setViewport(new osg::Viewport(traits->x, traits->y, traits->width, traits->height));
- // 添加相机到VIEWER
- //mViewer->addSlave(camera.get());
- mViewer->setCamera(camera);
- // 添加操作器到VIEWER 会影响图像,,,,
- mViewer->setCameraManipulator(keyswitchManipulator.get());
- //设置数据
- mViewer->setSceneData(mRoot.get());
- pickHandler = new PickModeHandler() ;
- mViewer->addEventHandler(pickHandler.get());
- //mViewer->addEventHandler(pickHandler);
- // 实现VIEWER
- mViewer->realize();
复制代码 谢谢! |
|