|
楼主 |
发表于 2017-12-15 11:17:13
|
显示全部楼层
- HWND hWnd= GetSafeHwnd();
- mOSG = new cOSG(GetSafeHwnd());
- mOSG->InitOSG("cow.osg");
- mThreadHandle = (HANDLE)_beginthread(&cOSG::Render,0,mOSG);
- return ;
- osgViewer::Viewer * viewer = new osgViewer::Viewer;
-
- RECT rect;
- osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
- osg::ref_ptr<osg::Referenced> windata = new osgViewer::GraphicsWindowWin32::WindowData(hWnd);
- // Setup the traits parameters
- 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 = viewer->getCamera();
- camera->setViewport(new osg::Viewport(traits->x, traits->y, traits->width, traits->height));
- camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
- camera->setClearColor(osg::Vec4f(0.2f, 0.2f, 0.4f, 1.0f));
- camera->setProjectionMatrixAsPerspective(
- 30.0f, static_cast<double>(traits->width)/static_cast<double>(traits->height), 1.0, 1000.0);
- camera->setGraphicsContext(gc);
- osg::ref_ptr<osgGA::TrackballManipulator> trackball = new osgGA::TrackballManipulator();
- viewer->setCameraManipulator(trackball);
- viewer->setCamera(camera);
- viewer->setSceneData(osgDB::readNodeFile("cow.osg"));
- viewer->realize();
- //viewer->run();
- viewer->frame();
- viewer->frame();
- viewer->frame();
- viewer->frame();
复制代码 |
|