osgEarth使用对数深度缓存

使用对数深度缓存可以在一定程度上解决z冲突(Z-Fighting),osgEarth也支持使用对数深度缓存,方法是:

    if ( useLogDepth )
    {
        OE_INFO << LC << "Activating logarithmic depth buffer (vertex-only) on main camera" << std::endl;
        osgEarth::Util::LogarithmicDepthBuffer logDepth;
        logDepth.setUseFragDepth( false );
        logDepth.install( view->getCamera() );
    }

    else if ( useLogDepth2 )
    {
        OE_INFO << LC << "Activating logarithmic depth buffer (precise) on main camera" << std::endl;
        osgEarth::Util::LogarithmicDepthBuffer logDepth;
        logDepth.setUseFragDepth( true );
        logDepth.install( view->getCamera() );
    }

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用GDAL库和OSGEarth库读取S57地图并显示在地球上的代码示例: ```c++ #include <osgEarth/MapNode> #include <osgEarth/Registry> #include <osgEarthUtil/EarthManipulator> #include <osgEarthUtil/LogarithmicDepthBuffer> #include <gdal_priv.h> #include <ogrsf_frmts.h> int main(int argc, char** argv) { // 初始化OSGEarthosgEarth::initialize(); // 创建地球模型 osg::ref_ptr<osgEarth::Map> map = new osgEarth::Map(); osgEarth::MapNodeOptions options; options.setMap(map.get()); osg::ref_ptr<osgEarth::MapNode> mapNode = new osgEarth::MapNode(options); // 添加地球模型到场景图中 osg::ref_ptr<osg::Group> root = new osg::Group(); root->addChild(mapNode.get()); // 添加地球控制器 osg::ref_ptr<osgEarth::Util::EarthManipulator> manipulator = new osgEarth::Util::EarthManipulator(); mapNode->setManipulator(manipulator.get()); // 开启对数深度缓冲 osg::ref_ptr<osg::StateSet> stateSet = root->getOrCreateStateSet(); osgEarth::Util::LogarithmicDepthBuffer depthBuffer; depthBuffer.install(stateSet.get()); // 打开S57文件 GDALAllRegister(); const char* filePath = "path/to/s57/file"; GDALDataset* dataset = (GDALDataset*)GDALOpenEx(filePath, GDAL_OF_READONLY | GDAL_OF_VECTOR, NULL, NULL, NULL); if (dataset == NULL) { osg::notify(osg::FATAL) << "Failed to open S57 file." << std::endl; return 1; } // 获取第一个图层 OGRLayer* layer = dataset->GetLayer(0); if (layer == NULL) { osg::notify(osg::FATAL) << "Failed to get layer." << std::endl; return 1; } // 创建图层地物图元 osg::ref_ptr<osgEarth::Features::FeatureSource> featureSource = new osgEarth::Features::OGRFeatureSource(layer); // 创建图层节点 osg::ref_ptr<osgEarth::Annotation::FeatureNode> featureNode = new osgEarth::Annotation::FeatureNode(mapNode.get(), featureSource.get()); // 添加图层节点到场景图中 root->addChild(featureNode.get()); // 运行OSG程序 osgViewer::Viewer viewer; viewer.setSceneData(root.get()); viewer.run(); // 关闭S57文件 GDALClose(dataset); // 关闭OSGEarthosgEarth::uninitialize(); return 0; } ``` 该代码主要在前面的基础上,添加了创建图层地物图元和图层节点的代码,以及添加图层节点到场景图中的代码。最后运行OSG程序并关闭S57文件和OSGEarth库。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值