|
楼主 |
发表于 2009-7-21 18:54:54
|
显示全部楼层
camera->apply()??
我就是想让相机在当前的函数范围内“按下快门”,将当前的场景留到Texture上。OverlayNode可能没有研究透彻,还是有点疑问。
这是我原来的函数(闪,应该是viewer的原因,却为什么连结果都不对??)。- void RenderToTexture(osg::Texture2D *texture2D, osg::Node *subGraph)
- {
- osg::Camera* camera = new osg::Camera;
- camera->setClearColor(osg::Vec4(0.0f,0.0f,0.0f,0.0f));
- camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- osg::BoundingBox box = subGraph->getBound();
- camera->setProjectionMatrixAsOrtho(box.xMin(), box.xMax(), box.yMin(), box.yMax(), 0.5, 0.0);
- camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
- camera->setViewMatrixAsLookAt(osg::Vec3(_centerX, _centerY, 1.0f),osg::Vec3(_centerX, _centerY, -1.0f),osg::Vec3(0.0f,1.0f,0.0f));
- camera->setViewport(0,0,256,256);
- camera->setRenderOrder(osg::Camera::PRE_RENDER);
- // tell the camera to use OpenGL frame buffer object where supported.
- camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
- camera->attach(osg::Camera::COLOR_BUFFER, texture2D);
- camera->addChild(subGraph);
- //预想运行一帧来获得渲染后的Texture。
- osgViewer::Viewer* viewer = new osgViewer::Viewer();
- osg::Group* root = new osg::Group();
- root->addChild(camera);
- osgUtil::Optimizer optimizer ;
- optimizer.optimize(root) ;
- viewer->setSceneData(root);
- viewer->realize();
- if (!viewer->getCameraManipulator() && viewer->getCamera()->getAllowEventFocus())
- {
- viewer->setCameraManipulator(new osgGA::TrackballManipulator());
- }
- viewer->setReleaseContextAtEndOfFrameHint(false);
- if (!viewer->done())
- {
- viewer->frame();
- viewer->frame();
- }
- viewer->setDone(true);
- camera->detach(osg::Camera::COLOR_BUFFER);
- delete viewer;
- }
复制代码 |
|