osg::Camera* createHUDCamera(double left, double right, double bottom, double top)
{
osg::ref_ptr<osg::Camera> camera = new osg::Camera();
camera->setProjectionMatrix(osg::Matrix::ortho2D(left, right, bottom, top));
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera->setViewMatrix(osg::Matrix::identity());
camera->setClearMask(GL_DEPTH_BUFFER_BIT);
camera->setRenderOrder(osg::Camera::POST_RENDER);
camera->setAllowEventFocus(false);
camera->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
return camera.release();
}
osg::Camera* createHUDNode(osg::Texture2D* texture)
{
osg::ref_ptr<osg::Camera> hud_camera = createHUDCamera(0, 500, 0, 400);
osg::ref_ptr<osg::Geode> geode = new osg::Geode();
geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture);
osg::ref_ptr<osg::Geometry> geometry = osg::createTexturedQuadGeometry(osg::Vec3(), osg::Vec3(100.0f, 0.0f, 0.0f), osg::Vec3(0.0f, 100.0f, 0.0f));
geode->addDrawable(geometry);
hud_camera->addChild(geode);
return hud_camera.release();
}
void createSlaveCamera(osgViewer::Viewer* viewer, osg::Texture2D* texture)
{
osg::ref_ptr<osg::GraphicsContext> gc = viewer->getCamera()->getGraphicsContext();
int width = gc->getTraits()->width;
int height = gc->getTraits()->height;
osg::ref_ptr<osg::Camera> camera = new osg::Camera();
camera->setRenderOrder(osg::Camera::PRE_RENDER);
camera->setGraphicsContext(gc);
camera->setViewport(0, 0, width, height);
camera->attach(osg::Camera::COLOR_BUFFER, texture);
viewer->addSlave(camera, osg::Matrixd::scale(5, 5, 5), osg::Matrixd::identity());
}
int main()
{
osgViewer::Viewer viewer;
viewer.setUpViewInWindow(0, 0, 500, 400);
viewer.realize();
osg::ref_ptr<osg::Group> group = new osg::Group();
osg::ref_ptr<osg::Node> cow = osgDB::readNodeFile("cow.osg");
group->addChild(cow);
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D();
texture->setInternalFormat(GL_RGBA);
group->addChild(createHUDNode(texture));
createSlaveCamera(&viewer, texture);
viewer.setSceneData(group);
return viewer.run();
}
RTT相机
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
网络监控摄像头通过OBS取流变身电脑摄像头
OBS 网络摄像头接入腾讯会议
Windows 视频流 用户名