前言

  上一篇编译了proj6.2.0、gdal3.2.1,本篇继续。

 

OsgEarth编译过程简介

  OsgEarth的编译,是基于Osg和OsgEarth结合在一起的,先要编译Osg,然后编译OsgEarth。OsgEarth的依赖库较多,分为上、中、下三篇,然后单独有一篇如何将编译好的osgEarth集成到Qt中。

 

目标:Qt5.15.x + VS2019 x64版本

 

演示Demo

  Demo基于Qt5.15.2 + vs2019 x64 + osg3.6.3 + osgEarth3.1。
  
  演示环境Demo下载地址:https://download.csdn.net/download/qq21497936/14984791

 

编译OsgEarth 3.1

步骤一:下载解压

   
  (备注:博主QQ群提供文件下载,博客首页有扫码加群)

步骤二:CMake配置,添加Curl

  

补充:没有添加Curl,则会报错如下:

  

步骤三:CMake配置,添加DGAL

   

补充:没有添加GDAL,则会报错如下:

  

步骤四:CMake配置,添加libZip

  

补充:没有添加libzip,则会报错如下:

  

步骤五:CMake配置,添加OSG

  

步骤六:CMake配置

  

步骤七:CMake生成工程

  

步骤八:打开工程编译

  

步骤九:编译错误“未定义GL_DYNAMIC_STORAGE_BIT”

  
  直接自己加个定义把,先找到他的定义:
  
  直接修改源码:
  

步骤十:编译成功

  
   

 

Demo源码

#include <osg/Notify>
#include <osgGA/StateSetManipulator>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgDB/WriteFile> #include <osgEarth/MapNode>
#include <osgEarth/GDAL>
#include <osgEarth/ExampleResources>
#include <osgEarth/EarthManipulator> #include <osgEarth/Style>
#include <osgEarth/OGRFeatureSource>
#include <osgEarth/FeatureModelLayer>
#include <osgEarth/FeatureImageLayer> using namespace osgEarth;
using namespace osgEarth::Util; const char* styles_css =
R"(
p {
altitude-clamping: terrain-drape;
render-backface-culling: false;
}
p1: p{ fill: #ff3f3f9f; }
p2: p{ fill: #3fff3f9f; }
p3: p{ fill: #3f3fff9f; }
p4: p{ fill: #ff3fff9f; }
p5: p{ fill: #ffff3f9f; }
)"; const char* script_source =
R"(
function getStyleClass()
{
// Exclude any countries beginning with the letter A:
if ( feature.properties.name.charAt(0) === 'A' )
return null; // If it starts with the letter C, return an inline style:
if ( feature.properties.name.charAt(0) == 'C' )
return '{ _fill: #ffc838; stroke: #8f8838; extrusion-height: 250000; }'; // Otherwise, return a named style based on some calculations:
var pop = parseFloat(feature.properties.pop);
if ( pop <= 14045470 ) return "p1";
else if ( pop <= 43410900 ) return "p2";
else if ( pop <= 97228750 ) return "p3";
else if ( pop <= 258833000 ) return "p4";
else return "p5";
}
)"; int main(int argc, char** argv)
{
osgEarth::initialize(); osg::ArgumentParser arguments(&argc, argv); bool useRaster = arguments.read("--rasterize");
bool useMem = arguments.read("--mem");
bool useLabels = arguments.read("--labels");
bool useDraping = arguments.read("--drape");
bool useClamping = arguments.read("--clamp");
bool useScript = arguments.read("--script"); std::string outfile;
arguments.read("--out", outfile); osgViewer::Viewer viewer(arguments); osg::ref_ptr<Map> map = new Map(); GDALImageLayer* basemap = new GDALImageLayer();
basemap->setURL("world.tif");
map->addLayer(basemap); // Next we add a layer to provide the feature data.
OGRFeatureSource* features = new OGRFeatureSource();
features->setName("vector-data"); if (useMem)
{
// the --mem options tells us to just make an in-memory geometry:
Ring* line = new Ring();
line->push_back(osg::Vec3d(-60, 20, 0));
line->push_back(osg::Vec3d(-120, 20, 0));
line->push_back(osg::Vec3d(-120, 60, 0));
line->push_back(osg::Vec3d(-60, 60, 0));
features->setGeometry(line);
}
else
{
features->setURL("world.shp");
}
map->addLayer(features); Style style; LineSymbol* ls = style.getOrCreateSymbol<LineSymbol>();
ls->stroke()->color() = Color::Yellow;
ls->stroke()->width() = 2.0f;
ls->tessellationSize()->set(100, Units::KILOMETERS); if (useDraping)
{
AltitudeSymbol* alt = style.getOrCreate<AltitudeSymbol>();
alt->clamping() = alt->CLAMP_TO_TERRAIN;
alt->technique() = alt->TECHNIQUE_DRAPE;
} else if (useClamping)
{
AltitudeSymbol* alt = style.getOrCreate<AltitudeSymbol>();
alt->clamping() = alt->CLAMP_TO_TERRAIN;
alt->technique() = alt->TECHNIQUE_GPU; ls->tessellationSize()->set(100, Units::KILOMETERS); RenderSymbol* render = style.getOrCreate<RenderSymbol>();
render->depthOffset()->enabled() = true;
} if (useRaster)
{
FeatureImageLayer* layer = new FeatureImageLayer();
layer->setFeatureSource(features);
StyleSheet* sheet = new StyleSheet();
sheet->addStyle(style);
layer->setStyleSheet(sheet);
map->addLayer(layer);
} else
{
FeatureModelLayer* layer = new FeatureModelLayer();
layer->setFeatureSource(features); StyleSheet* styleSheet = new StyleSheet(); if (useScript)
{
styleSheet->addStylesFromCSS(styles_css);
styleSheet->setScript(new StyleSheet::ScriptDef(script_source));
styleSheet->addSelector(StyleSelector("default", StringExpression("getStyleClass()")));
}
else
{
styleSheet->addStyle(style);
} layer->setStyleSheet(styleSheet);
map->addLayer(layer);
} if (useLabels && !useRaster)
{
Style labelStyle; TextSymbol* text = labelStyle.getOrCreateSymbol<TextSymbol>();
text->content() = StringExpression("[name]");
text->priority() = NumericExpression("[pop]");
text->size() = 16.0f;
text->alignment() = TextSymbol::ALIGN_CENTER_CENTER;
text->fill()->color() = Color::White;
text->halo()->color() = Color::DarkGray; StyleSheet* sheet = new StyleSheet();
sheet->addStyle(labelStyle); FeatureModelLayer* fml = new FeatureModelLayer();
fml->setName("Labels");
fml->setFeatureSource(features);
fml->setStyleSheet(sheet);
map->addLayer(fml);
} LayerVector layers;
map->getLayers(layers);
for (LayerVector::const_iterator i = layers.begin(); i != layers.end(); ++i)
{
Layer* layer = i->get();
if (layer->getStatus().isError() &&
layer->getEnabled())
{
OE_WARN << layer->getName() << " : " << layer->getStatus().toString() << std::endl;
}
} MapNode* mapNode = new MapNode(map.get()); if (!outfile.empty())
{
OE_NOTICE << "Writing to " << outfile << std::endl;
osgDB::writeNodeFile(*mapNode, outfile);
}
else
{
viewer.setSceneData(mapNode);
viewer.setCameraManipulator(new EarthManipulator()); MapNodeHelper().configureView(&viewer); return viewer.run();
}
}
 
 

若该文为原创文章,转载请注明原文出处
本文章博客地址:https://blog.csdn.net/qq21497936/article/details/113541346

最新文章

  1. python 版本升级(CentOS) 从2.6.6升级到2.7.6
  2. PopupWindow+ListView+OnItemClick点击无效
  3. PHP Socket实现websocket(二)Socket函数
  4. pthread_create传递参数
  5. ted be grateful
  6. 初探接口测试框架--python系列3
  7. 应用层open(read、write、close)怎样调用驱动open(read、write、close)函数的?
  8. 如何在 Windows Phone 8 中获取手机的当前位置
  9. v9.5.2上传缩略图/附件提示“undefined”
  10. C语言老司机学Python (六)- 多线程
  11. Struts 2 之 OGNL
  12. 【算法导论】第i小的元素
  13. MySQL:进阶之视图函数
  14. HTTP请求中POST与GET的区别
  15. linux timing profile
  16. java-Timer类使用方法
  17. ORA-01591 锁定已被有问题的分配事务处理--解决方法(转)
  18. linux系统查毒软件ClamAV
  19. 20145324王嘉澜《网络对抗技术》web安全基础实践
  20. Eclipse launch configuration----Eclipse运行外部工具

热门文章

  1. C++ 入门篇
  2. 【C++】《C++ Primer 》第十四章
  3. Docker 介绍和安装(一)
  4. 在 Azure 上执行一些简单的 python 工作
  5. linux之curl工具
  6. LeetCode965. 单值二叉树
  7. ctfshow—web—web签到题
  8. 集成多种协议、用于 USB-A 和 TYPE-C 双端口输出的快充协议芯片IP2726
  9. CMOS 摄像头的Skipping 和 Binning 模式
  10. 支付宝沙箱环境使用(Alipay Easy SDK ) .Net示例