osgEarth初探

osgEarth是基于OpenSceneGraph (OSG)开发的三维地图SDK,......(此处省略500凑字数的内容)。

基础环境配置

为了避免繁琐的源码编译过程,使用vcpkg安装osgEarth,安装成功后,单独导出来。

  • 安装: vcpkg install osgEarth --keep-going
  • 导出:vcpkg export osgEarth:x64-windows --raw --output=osgEarth --output-dir=E:/

其中,--raw表示以文件夹形式导出,--output表示导出文件夹名称,--output-dir表示导出文件夹位置。

使用Microsoft Visual Stuido 2022建立一个控制台应用程序,在属性页中进行如下配置:

  1. 附加包含目录:E:/osgEarth/installed/x64-windows/include
  2. 附加库目录:E:/osgEarth/installed/x64-windows/debug/lib
  3. 附加依赖项:*.lib
  4. 调试环境:path=E:/osgEarth/installed/x64-windows/debug/bin

如果使用 vcpkg integrate install进行Visual Studio集成,则无需进行上述属性配置过程。

加载官网示例

在osgEarth源码中给出了一个基本的使用示例,如下所示:

cpp 复制代码
#include <osgEarth/MapNode>
#include <osgEarth/TMS>
#include <osgEarth/EarthManipulator>
#include <osgEarth/GLUtils>
#include <osg/ArgumentParser>
#include <osgViewer/Viewer>

int main(int argc, char** argv)
{
    osgEarth::initialize();
  
    osg::ArgumentParser args(&argc, argv);
    osgViewer::Viewer viewer(args);
    viewer.setRealizeOperation(new osgEarth::GL3RealizeOperation());
  
    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);
    viewer.setCameraManipulator(new osgEarth::EarthManipulator(args));
  
    return viewer.run();
}

上述示例代码正常运行后,会出现一个三维地球。

将示例代码拷贝到 main.cpp中。此时,编译项目会报出一大堆乱七八糟的错误,在第一行添加 #include<Windows.h>即可解决。再次编译,仍然出现了一些错误,在 #include<Windows.h>前添加 #define NOMINMAX即可解决。

运行程序,在控制台中可能会报出如下几个错误:

  1. Fontconfig error: Cannot load default config file: No such file: (null)
  2. Error reading file C:/Windows/fonts\verdana.ttf: file not handled
  3. osgEarth* FAILED to create a terrain engine for this map

对于错误1,参考FontConfig osg OsgEarth Fontconfig error: Cannot load default config file: No such file: (null) · Issue #25776 · microsoft/vcpkg将【.../installed/x64-windows/etc/】位置下的【fonts】文件夹直接拷贝到exe同级目录下问题解决。

对于错误2,该错误是在没有使用 vcpkg integrate install进行Visual Studio集成的情况下出现。根据osg OpenSceneGraph Could not find plugin to read objects from file "xxxx".) Error writing_error reading file simpleroom.osgt: read error (co-CSDN博客,灵机一动下,将【osgPlugin-3.6.5】配置到项目(配置到调试环境或将该文件夹拷贝到exe同级目录下 )中,问题解决。

对于错误3,该错误是在使用 vcpkg integrate install进行Visual Studio集成的情况下出现。与错误2解决办法相同。

上述错误处理完毕后,运行程序,出现想要的结果:

相关推荐
Full Stack Developme2 分钟前
SpringBoot 内嵌 Tomcat 的启动流程
spring boot·后端·tomcat
IT_陈寒20 分钟前
Vue的这个响应式陷阱,我调试了一整天才爬出来
前端·人工智能·后端
snow@li21 分钟前
Spring 项目 Java 访问修饰符 + 非访问修饰符全景梳理详解
java·后端·spring
大模型念念28 分钟前
Spring 框架入门:从零开始构建你的第一个应用
java·后端·spring
SilentSlot32 分钟前
【C/C++】手写 DPDK 协议栈(十二):TCP 并发与自实现 epoll 的就绪事件分发
c语言·c++·tcp/ip
卷无止境36 分钟前
Python 相对导入与绝对导入的坑:从原理到工程实践
后端·python
SilentSlot40 分钟前
【C/C++】手写 DPDK 协议栈(六):TCP 三次握手、状态机与数据回显
c语言·c++·tcp/ip
卷无止境43 分钟前
Python调试那点事儿:从pdb到日志系统的实战指南
后端·python
乱七八糟的屋子43 分钟前
AMQP C++ 超详细实战教程(amqp-cpp 开源库从零入门到生产落地)
c++·rabbitmq·任务队列·amqp·流量削峰·c++服务端异步解耦·分布式消息通信
Escalating_xu1 小时前
C++11 彻底吃透 emplace_back 与 push_back(最全闭环:左右值|深浅拷贝|移动构造|万能引用|完美转发)
开发语言·c++