windows10使用vcpkg编译osgearth3.0

官网说明:http://docs.osgearth.org/en/latest/build.html

安装vcpkg:

1、首先需要安装git,这个过程略;

2、然后下载并编译安装:可以通过git下载可以下载源码包:https://github.com/Microsoft/vcpkg

// 下载源码
C:\src\>git clone https://github.com/Microsoft/vcpkg.git

//运行构建vcpkg.exe
C:\src\>cd vcpkg
C:\src\vcpkg>bootstrap-vcpkg.bat

3、运行如下命令使计算机的所有用户都可以使用vcpkg (备注:需要管理员权限)

vcpkg integrate install

>> CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=C:/Sofe/vcpkg-master/scripts/buildsystems/vcpkg.cmake"

 

4、 安装osgearth需要的各种依赖库:

vcpkg install osg:x64-windows sqlite3:x64-windows protobuf:x64-windows poco:x64-windows

这个步骤其实很漫长,有些包很大,下载不下来就按照提示复制地址使用迅雷下载,然后拷贝到vcpkg\download下,并重启安装库命令;

由于网络问题,我在安装过程中遇到了几个包依赖,比如GDAL、LIBZIP、ROCKSDB等,手动单独安装一下就好了,

补充:我后来发现有些问题是缺少库造成的,所以还需要将boost库以及osg[plugins]也安装上,否则就会有问题。

boost的安装见我下一个帖子:

./vcpkg.exe install osg[plugins]:x64-windows

 

5、执行编译OSGEARTH,我是下载了3.0的压缩包,也可以使用GIT拖下来:

git clone https://github.com/gwaldron/osgearth.git

准备编译:

cd osgearth

mkdir build

cd build

配置CMAKE

 cmake  ..  -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=Release  -DWIN32_USE_MP=ON  -DCMAKE_TOOLCHAIN_FILE=D:\vcpkg\scripts\buildsystems\vcpkg.cmake

 

网络教程使用命令行编译,

cmake --build . --target INSTALL --config Release

我是直接用VS2017打开了那个sln解决方案,在编译过程中遇到了2个问题:都是关于GEOS.cpp的:

1)66行,从智能指针转换为普通的指针,需要执行get(),并转换:

geom::CoordinateSequence* seq = (geom::CoordinateSequence*)factory->create( coords ).release();

2)170行的从父类到派生类指针的需要动态或者强制转换:我喜欢硬来,

 output = f->createPolygon( shell, (std::vector<geom::LinearRing*>*)holes );

改完这2个位置就能编译了;我的编译设置是X64, 多字节集方式;

但是建议使用osgearth3.1版本,从官网下载ZIP包,解开,按照前文命令生成SLN项目文件,就可以编译;

需要说明的是:

1)设置输出目录为data以及tests的同级目录,比如 osgearth/DebugBin/,这样方便测试以及示例程序中的代码直接使用各种资源文件。

2)项目core是核心的库,必须要编译的;

3)各种plugin都是要编译的;不然测试时候出错;

4)我编译了 osgEarth_tests项目,并启动,检测各种设置是否正常;

5)我直接编译了 tools下的Tool osgearth_viewer项目,同样设置输出目录以及启动目录,但是由于默认的配置在不科学上网的情况下打不开相关的页面,在参数里面设置../tests/boston.earth

所以我自己重找了一个earth文件,并使用了openstreetmap的相关的地址;如下

<!--
osgEarth Sample.

Demonstrates the use of a Resource Library in order to apply "typical" textures
to extruded buildings.
-->

<map name="Boston Demo" type="geocentric" version="2">

    <options elevation_tile_size="15" overlay_resolution_ratio="1">
        <terrain lighting="false"/>
        <cache type="filesystem">
            <path>cache</path>
        </cache>
        <cache_policy usage="no_cache"/>
        <!-- <cache_policy usage="cache_only"/> -->
    </options>

    <image name="osm_mapnik" driver="xyz">
        <url>http://[abc].tile.openstreetmap.org/{z}/{x}/{y}.png</url>
        <profile>spherical-mercator</profile>
    </image>

<!--
    <image name="readymap_imagery" driver="tms">
        <url>http://readymap.org/readymap/tiles/1.0.0/22/</url>
        <color_filters>
            <gamma rgb="1.3"/>
        </color_filters>
    </image>

    <elevation name="readymap_elevation" driver="tms">
        <url>http://readymap.org/readymap/tiles/1.0.0/9/</url>
    </elevation>
-->

    <model name="buildings" driver="feature_geom">
        <features name="buildings" driver="ogr">
            <url>data/boston_buildings_utm19.shp</url>
            <build_spatial_index>true</build_spatial_index>
        </features>

        <layout tile_size_factor="52">
            <level name="default" max_range="20000" style="buildings"/>
        </layout>

        <styles>
            <library name="us_resources">
                <url>data/resources/textures_us/catalog.xml</url>
            </library>

            <style type="text/css">
                buildings {
                    extrusion-height:        3.5 * max([story_ht_], 1);
                    extrusion-flatten:       true;
                    extrusion-wall-style:    building-wall;
                    extrusion-wall-gradient: 0.8;
                    extrusion-roof-style:    building-rooftop;
                    altitude-clamping:       terrain;
                    altitude-technique:      map;
                    altitude-binding:        vertex;
                }
                building-wall {
                    skin-library:     us_resources;
                    skin-tags:        building;
                    skin-random-seed: 1;
                    fill:             #ffffff;
                }
                building-rooftop {
                    skin-library:     us_resources;
                    skin-tags:        rooftop;
                    skin-tiled:       true;
                    skin-random-seed: 1;
                    fill:             #ffffff;
                }
            </style>
        </styles>
    </model>

    <external>
        <viewpoints>
            <viewpoint name="Home" heading="-25" height="50" lat="42.355" long="-71.068" pitch="-90" range="480"/>
            <viewpoint name="Bird's eye" heading="24" height="50" lat="42.355" long="-71.068" pitch="-20" range="1000"/>
            <viewpoint name="Overview" heading="24.261" height="0" lat="42.34425" long="-71.076262" pitch="-21.6" range="3450"/>
            <viewpoint name="Downtown 1" heading="117" lat="42.3568" long="-71.0585" height="0" pitch="-20.4" range="1500" />
            <viewpoint name="Downtown 2" heading="-128.5" lat="42.3582" long="-71.0546" height="0" pitch="-19" range="1620" />
            <viewpoint name="Street Level" heading="-193" lat="42.3569" long="-71.07" pitch="0" height="20" range="85"/>
        </viewpoints>
        <sky hours="14.0"/>
    </external>
</map>

 

编译好了就可以设置环境变量了:

在PATH中添加:osg的各种DLL,插件的DLL,OE的各种DLL
D:\vcpkg\installed\x64-windows\debug\bin
D:\vcpkg\installed\x64-windows\tools\osg
D:\OSG\osgearth\build\lib\Debug

备注:我在运行时候遇到一个错误,提示缺少libfontconfig-1.dll,经过折腾以后,我发现把fontconfig-1.dll复制一份,改成缺的名字,然后就可以运行了,

具体为啥不清,一般来说linux会自己加上前缀,windows一般不加。

但是启动时候仍然提示无法加载默认的fontconfig文件,不知道如何配置,有知道的请指导一下。

 

如果不想自己编译,可以执行命令直接安装,但是我没有这么干,因为网上有人说这个版本有点问题,可能缺少DEBUG版本,无法调试。

vcpkg install osgearth:x64-windows

补充一下:

亲测不用科学online的地图:

<!--高德道路地图为: -->
<image name="mapbox_satellite" driver="xyz">
        <url>http://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&amp;size=1&amp;scale=1&amp;style=8&amp;x={x}&amp;y={y}&amp;z={z}</url>
        <profile>spherical-mercator</profile>
</image>

<!--高德卫星地图为-->

<image name="mapbox_satellite" driver="xyz">
        <url>http://webst04.is.autonavi.com/appmaptile?style=6&amp;x={x}&amp;y={y}&amp;z={z}</url>
        <profile>spherical-mercator</profile>
</image>

设置代理的参数:

比如使用小飞机上网,则设置在image同级,

<proxy_host>127.0.0.1</proxy_host>
<proxy_port>1080</proxy_port>

高程的加载:

<heightfield name="terrain" driver = "gdal">
      <url>D:/SRTM3v90</url>
	  <extensions>hgt</extensions>  
      <tile_size>32</tile_size>
	</heightfield>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值