参照官方教程,完成OSGEarth的配置

(说明:小白查阅其他教程,结合试错法得出的配置教程)

转载请注明出处。

1.参照官方教程配置

官方教程链接:

Getting started with osgEarth

Getting started with osgEarth — osgEarth 3.5 documentation

注意事项

“Update the OpenSceneGraph vcpkg build”这一步更改“GL2”为“GL3”必不能少。

如果已经在没改为“GL3”的情况下vcpkg安装过osg、osgearth,先要用vcpkg卸载后,再重新安装。

2.完成build后,VS中项目属性的更改

2.1 dll文件相关


2.1.1 dll文件的链接

可分别建立“releaseDll”、“debugDll”文件夹,然后在项目属性的“调试/环境”中添加“path=对应模式的dll文件夹所在路径”。
如:


 
2.1.2 debug模式所需复制的dll文件


从项目目录下的“build\vcpkg_installed\x64-windows\debug”中搜索“*.dll”和“*.pdb”,全部复制到“debugDll”文件夹。


2.1.3 release模式所需复制的dll文件


复制项目目录下的“build\vcpkg_installed\x64-windows”文件夹到任意某处,然后删除其中的debug文件夹,搜索“*.dll”,然后复制所有dll到“releaseDll”文件夹。


2.2 debug模式的“附加依赖项”更改


更改debug配置的“附加依赖项”中的“vcpkg_installed\x64-windows\lib\osgEarthd.lib”为build文件夹下的“vcpkg_installed\x64-windows\debug\lib\osgEarthd.lib”。

不进行此步骤,debug模式无法使用,一使用就触发断点报错。

3 测试用例

#include <osgEarth/MapNode>
#include <osgEarth/TMS>
#include <osgEarth/EarthManipulator>

#include <osgDB/ReadFile>
#include <osgEarth/Common>
#include <gdal_priv.h>
#include <ogr_api.h>
#include <ogr_core.h>
#include <ogr_feature.h>
#include <ogr_geometry.h>
#include <ogrsf_frmts.h>

#include <iostream>
#include <osgViewer/Viewer>
#include <osg/Vec3d>
#include <osg/MatrixTransform>
#include <osgDB/ReadFile>

#include <osgEarth/EarthManipulator>
#include <osgEarth/MapNode>
#include <osgEarth/GDAL>
#include <osgEarth/OGRFeatureSource>
#include <osgEarth/FeatureImageLayer>
#include <osgEarth/GeoTransform>

#include <osg/ArgumentParser>
#include <osgViewer/Viewer>

//部分代码参考:
https://blog.csdn.net/Being__/article/details/125709041

int main(int argc, char** argv)
{
    osgEarth::initialize();
	osg::ArgumentParser args(&argc, argv);
	osgViewer::Viewer viewer(args);

	//-------------https://docs.osgearth.org/en/latest/install.html
    
	//auto imagery = new osgEarth::TMSImageLayer();
	//imagery->setURL("https://readymap.org/readymap/tiles/1.0.0/7/");
	//auto mapNode = new osgEarth::MapNode();
	//mapNode->getMap()->addLayer(imagery);
	//viewer.setSceneData(mapNode);

	//---------------------------


	// map,效果见图
	osg::Node* globe = osgDB::readNodeFile("annotation.earth");
	osgEarth::MapNode* mapNode = osgEarth::MapNode::get(globe);
	viewer.setSceneData(mapNode);


    viewer.setCameraManipulator(new osgEarth::EarthManipulator(args));
	viewer.setUpViewInWindow(100, 100, 800, 600);
    
    return viewer.run();
}


使用annotation.earth文件的效果图,如下:


代码中的annotation.earth文件源自OSGEarth在github的源码:

https://github.com/gwaldron/osgearth/tags
使用时需复制到项目目录下。

  • 18
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值