3D库比较多,一般学习的有PCL的VTK,库比较大,集成了相当多不错的算法,对开发水平是个考验;OGRE由于其插件式架构,使得在机器人开发方面应用广泛;相对而言,OSG比较小众,可以用来构建模拟仿真的的场景图。

当然,不论你学习哪个库,道理都是一样的,就是要去熟悉那些API,快速上手应用。

OSG的编译在这里,

3D进阶之OSG: VS2019编译OpenSceneGraph_高精度计算机视觉的博客-CSDN博客首先,这里已经有人给出了个省事的解决方案,我给个链接,OSG3.6.5+VS2019:免编译,在VS2019中新建OSG项目运行OSG_乔木cc的博客-CSDN博客_vs2019配置osg本博客资源链接_杨石兴的博客-CSDN博客链接:https://pan.baidu.com/s/101IXFgvKQhQOEbfLa-ztZg提取码:osgb到这个链接里,找到vs2019的编译库和第三方依赖,就可以开始工作了。然后,我想说的是, 如果你想编译这些第三方依赖库,和OSG,其实也不难,.https://blog.csdn.net/tanmx219/article/details/123943131你可以选择自己编译,也可以vcpkg安装编译,也有已经编译好的二进制可执行文件。

言归正传,下面我们开始OSG的开发之旅。

什么是osgEarth

这玩意就是把osg的很多功能做了一次封装。

安装 osgEarth

使用vcpkg的话,只需要一句指令,

vcpkg install osgearth:x64-windows

官方参考地址,

cInstalling osgEarth — osgEarth 3.1 documentation

编译osgEarth

作为开发者,我总想自己编译看看问题所在。官方地址是,

Building osgEarth — osgEarth 3.1 documentation

开发默认是vs2017,使用包管理工具vcpkg。关于如何使用vcpkg+vs2019可以参考我前面的博文,VS2017类似,

Tools_vcpkg包管理工具在VS2019项目开发中的使用_高精度计算机视觉的博客-CSDN博客

虽然本人的最终项目计划用qtcreator来实现;不过,在学习的过程中,VS还是必须的。下面我用VS2019实现编译。编译过程这段摘自官网,我做了一些注释,

(方法一)按照官网的办法

Building with vcpkg

vcpkg is an extremely useful package manager. It works on Windows, Linux and MacOS but for this guide we will focus on Windows.

Step 1 - Configure vcpkg

First, download and bootstrap vcpkg following the instructions on the page.

Next install the dependencies required to build a fully functional osgEarth. This example assume s 64-bit Windows build; you can alter that to correspond to your platform/architecture of choice.

Install the required dependencies:

vcpkg install osg:x64-windows gdal:x64-windows curl:x64-windows

For full functionality, you can install optional dependences as well:

vcpkg install sqlite3:x64-windows protobuf:x64-windows geos:x64-windows blend2d:x64-windows libwebp:x64-windows basisu:x64-windows draco:x64-windows libzip:x64-windows

This will take awhile the first time you run it as this pulls down lots of dependencies, so go get a cup of coffee.

Once all the dependencies are built, you’ll need to actually build osgEarth.

说明:

在这一步里,我实际只安装osg和gdal这两个必要的包,curl这样的工具在系统里已经安装 了,所以我直接跳过。

另外一点就是,如果后面发现需要安装其他包的时候,回过来再安装也不迟。

嗯,这杯咖啡耗时比较长。

Step 2 - Clone the repository

Pull down the source from GitHub and create a build folder for your out-of-source build. We always recommend doing an out-of-source build to avoid problems down the road!

git clone --recurse-submodules https://github.com/gwaldron/osgearth.git osgearth
mkdir build

This will clone the repository into a folder called osgearth and pull down all the submodules.

说明

科学上网,git直接下载就好了。

Step 3 - Configure CMake

vcpkg provides a CMake toolchain file that helps osgEarth find all of its dependencies.

Note: You’ll need to specify a different build directory based on your build configuration (Release, RelWIthDebInfo, Debug) and specify the build type using -DCMAKE_BUILD_TYPE. This is because some dependencies of osgEarth don’t pick up both debug and release versions without specifying the build type. Hopefully this will be fixed in future CMake versions.

Most developers will use a RelWithDebInfo build, like so:

cmake -S osgearth -B build -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DWIN32_USE_MP=ON -DCMAKE_INSTALL_PREFIX=[installroot] -DCMAKE_TOOLCHAIN_FILE=[vcpkgroot]\scripts\buildsystems\vcpkg.cmake

说明

这里面有些参数要改成自己的,例如,我用的VS2019,

cmake -S osgearth -B build -G "Visual Studio 16 2019 Win64" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DWIN32_USE_MP=ON -DCMAKE_INSTALL_PREFIX=[installroot] -DCMAKE_TOOLCHAIN_FILE=D:\vs3D\vcpkg\scripts\buildsystems\vcpkg.cmake

Step 4 - Build and install osgEarth

You can build and install osgEarth on the command line using CMake or you can open up the Visual Studio solution and build it from there.

cmake --build build --target INSTALL --config RelWithDebInfo

说明

这里会生成的项目,一般会有报错,可以用VS2019打开进行编译与调试。

Step 5 - Set up your runtime environment

You’ll need to make sure that the vcpkg dependencies and osgEarth are in your path:

set PATH=%PATH%;c:\vcpkg\installed\x64-windows\bin
set PATH=%PATH%;c:\vcpkg\installed\x64-windows\tools\osg
set PATH=%PATH%;[installroot]

碰到的问题

报错如下所示

1>------ 已启动生成: 项目: osgEarth, 配置: RelWithDebInfo x64 ------
1>MapboxGLImageLayer.cpp
1>MapboxGLGlyphManager.cpp
1>D:\osgprj\osgearth\src\osgEarth\MapboxGLGlyphManager.cpp(25,10): fatal error C1083: 无法打开包括文件: “glyphs.pb.h”: No such file or directory
1>D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp(258,27): error C2065: “MVTFeatureSource”: 未声明的标识符
1>D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp(258,18): error C2923: “osg::ref_ptr”: 对于参数“T”,“MVTFeatureSource”不是有效的 模板 类型变量
1>D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp(258): message : 参见“MVTFeatureSource”的声明
1>D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp(258,66): error C2061: 语法错误: 标识符“MVTFeatureSource”
1>D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp(258,60): error C2512: “osg::ref_ptr”: 没有合适的默认构造函数可用
1>D:\vs3D\vcpkg\installed\x64-windows\include\osg/ref_ptr(32,1): message : 参见“osg::ref_ptr”的声明 (编译源文件 D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp)
1>D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp(259,26): error C2678: 二进制“->”: 没有找到接受“osg::ref_ptr”类型的左操作数的运算符(或没有可接受的转换)
1>D:\vs3D\vcpkg\installed\x64-windows\include\osg/ref_ptr(106,12): message : 可能是“T *osg::ref_ptr::operator ->(void) const” (编译源文件 D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp)
1>D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp(259,26): message : 尝试匹配参数列表“(osg::ref_ptr)”时
1>D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp(259,28): error C2039: "setReadOptions": 不是 "osg::ref_ptr" 的成员
1>D:\vs3D\vcpkg\installed\x64-windows\include\osg/ref_ptr(32): message : 参见“osg::ref_ptr”的声明
1>D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp(260,26): error C2678: 二进制“->”: 没有找到接受“osg::ref_ptr”类型的左操作数的运算符(或没有可接受的转换)
1>D:\vs3D\vcpkg\installed\x64-windows\include\osg/ref_ptr(106,12): message : 可能是“T *osg::ref_ptr::operator ->(void) const” (编译源文件 D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp)
1>D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp(260,26): message : 尝试匹配参数列表“(osg::ref_ptr)”时
1>D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp(260,28): error C2039: "setURL": 不是 "osg::ref_ptr" 的成员
1>D:\vs3D\vcpkg\installed\x64-windows\include\osg/ref_ptr(32): message : 参见“osg::ref_ptr”的声明
1>D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp(261,26): error C2678: 二进制“->”: 没有找到接受“osg::ref_ptr”类型的左操作数的运算符(或没有可接受的转换)
1>D:\vs3D\vcpkg\installed\x64-windows\include\osg/ref_ptr(106,12): message : 可能是“T *osg::ref_ptr::operator ->(void) const” (编译源文件 D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp)
1>D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp(261,26): message : 尝试匹配参数列表“(osg::ref_ptr)”时
1>D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp(261,28): error C2039: "open": 不是 "osg::ref_ptr" 的成员
1>D:\vs3D\vcpkg\installed\x64-windows\include\osg/ref_ptr(32): message : 参见“osg::ref_ptr”的声明
1>D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp(262,48): error C2662: “T *osg::ref_ptr::get(void) const”: 不能将“this”指针从“osg::ref_ptr”转换为“const osg::ref_ptr &”
1>D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp(262,48): message : 原因如下: 无法从“osg::ref_ptr”转换为“const osg::ref_ptr”
1>D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp(262,30): message : 转换要求第二个用户定义的转换运算符或构造函数
1>D:\vs3D\vcpkg\installed\x64-windows\include\osg/ref_ptr(117,12): message : 参见“osg::ref_ptr::get”的声明 (编译源文件 D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp)
1>D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp(1274,48): warning C4018: “>=”: 有符号/无符号不匹配
1>D:\osgprj\osgearth\src\osgEarth\MapboxGLImageLayer.cpp(1274,73): warning C4018: “>=”: 有符号/无符号不匹配
1>已完成生成项目“osgEarth.vcxproj”的操作 - 失败。

我们一个个来,

(1)fatal error C1083: 无法打开包括文件: “glyphs.pb.h”: No such file or directory

这个一看就知道是pb.h这种需要protobuf生成的文件,我搜索了一下,找到了2个proto文件,为了避免找不到生成文件,单独搞了文件夹,

D:\osgprj\temp\glyphs.proto
D:\osgprj\temp\vector_tile.proto

然后找到protoc.exe运行下面的脚本,我用的protobuf3.7,自己在电脑上编译的,当然也可以直接到官网上去下载,用起来都一样,

下载地址在这里,

https://github.com/protocolbuffers/protobuf/releases?page=7

命令使用的方式如下,

protoc --proto_path=D:/osgprj/temp --cpp_out=D:/osgprj/temp D:/osgprj/temp/glyphs.proto
protoc --proto_path=D:/osgprj/temp --cpp_out=D:/osgprj/temp D:/osgprj/temp/vector_tile.proto

protobuf的版本要保持和OSG一致,比如在我下载的第三方库地址是,

E:\vOSG\3rdpartyVs2019x64\include\google\protobuf\port_def.inc

里面定义了

#define PROTOBUF_VERSION 3007000

当然,另一个办法是你随便用一个版本生成glyphs.pb.h和vector_file.pb.h之后,把里面的版本信息改成一致(显然不是一个好办法)。

最后会生成

glyphs.pb.h,  glyphs.pb.cpp,vector_tile.pb.h, vector_tile.pb.cpp

把生成文件拷贝到到项目中去,再编译就OK了。当然,要记得把libprotobuf.lib链接添加进项目里去。

(2)MapboxGLImageLayer.cpp(258,27): error C2065: “MVTFeatureSource”: 未声明的标识符

这个在项目预处理器中定义一个参数OSGEARTH_HAVE_MVT就好了。

(3)错误    LNK2001    无法解析的外部符号 "class google::protobuf::internal::ExplicitlyConstructed<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > google::protobuf::internal::fixed_address_empty_string" (?fixed_address_empty_string@internal@protobuf@google@@3V?$ExplicitlyConstructed@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@123@A)    osgEarth    D:\osgprj\build\src\osgEarth    D:\osgprj\build\src\osgEarth\glyphs.pb.obj    1

这个是protobuf的编译方式引起的,如果你用的static静态库, 一般就不会有这个错误;因为我用的是DLL动态库,所以在生成的.pb.h头文件中需要加上这么一句,

#ifndef PROTOBUF_glyphs_2eproto__INCLUDED
#define PROTOBUF_glyphs_2eproto__INCLUDED

#define PROTOBUF_USE_DLLS  // 这个是新添加的

#include <string>

(方法二)cmake-gui编译

编译时用到的第三方库参考此贴

3D进阶之OSG: VS2019编译OpenSceneGraph_高精度计算机视觉的博客-CSDN博客首先,这里已经有人给出了个省事的解决方案,我给个链接,OSG3.6.5+VS2019:免编译,在VS2019中新建OSG项目运行OSG_乔木cc的博客-CSDN博客_vs2019配置osg本博客资源链接_杨石兴的博客-CSDN博客链接:https://pan.baidu.com/s/101IXFgvKQhQOEbfLa-ztZg提取码:osgb到这个链接里,找到vs2019的编译库和第三方依赖,就可以开始工作了。然后,我想说的是, 如果你想编译这些第三方依赖库,和OSG,其实也不难,.https://blog.csdn.net/tanmx219/article/details/123943131同样,配置看图,

Configure + Generate之后,打开vs2019,一路编译过来,基本没有问题。

本文结束

3D进阶之OSG:从VS2019编译osgEarth开始相关推荐

  1. 3D进阶之OSG:快捷键

    OSG有不少快捷键,比如我们最常用的 t ==> texture s ==> statistics f ==> full screen h ==> help l ==> ...

  2. OSG开发笔记(一):OSG介绍、编译

    ​​​​​​​OSG开发专栏(点击传送门) 上一篇:无 下一篇:<OSG开发笔记(二):OSG帮助文档编译> 前言 需要用到三维立体变换.三维球体等三维开发,之前准备使用opengl,但是 ...

  3. 使用CMake编译OsgEarth

    编译OsgEarth之前需要编译依赖的Lib: 1.编译OSG VS2015+QT5.10+x64编译OSG 2.编译Geos 使用CMake编译Geos3.5.0 3.编译GDAL 使用nmake编 ...

  4. vs2019 编译 WRK 踩坑记录

    一.回顾 上一篇博客介绍了命令行编译 WRK 到调试的所有步骤,理论上我们已经可以开始学习了. 但是 IDE 可以方便的查找和修改函数,好处多多,所以这篇博客介绍如何使用 visual studio ...

  5. VS2019编译 当前最新版chromium

    VS2019编译 当前最新版chromium 之前编译过webrtc和chromium, 由于长时间没用,被我删除了, 最近在最新版本的google浏览器上遇到了播放器兼容性问题,老版本的google ...

  6. 在Unity 3D中,shader是何时编译的,在何时加载入显存中的?

    在Unity 3D中,shader是何时编译的,在何时加载入显存中的? 是某一对象在实例化时,加载其相关的material与shader还是游戏开始时? 添加评论 分享 按时间排序按投票排序 4 个回 ...

  7. SeetaFace2-master在Windows10 VS2019编译的两种方法

    SeetaFace2-master在Windows10 VS2019编译的两种方法 SeetaFace2简介 方法一 方法二 SeetaFace2简介 SeetaFace2 是一个完整的人脸识别项目, ...

  8. Win10中用VS2019编译live555

    前言 说明,本文是在Win10中用VS2019编译live555的过程中,对遇到的问题进行说明.编译过程主要参考的是下面一篇文章,在此表示感谢: https://blog.csdn.net/m0_37 ...

  9. VS2019编译MQTT库 C/C++(超详细,含示例工程)

    目录 前言 一.前期准备 1.1 获取mqtt库 1.2 安装openssl 1.3 安装cmake-gui 二.生成C工程代码 三.编译C库 3.1 创建工程目录 3.2 修改输出目录 四.生成C+ ...

最新文章

  1. AI一分钟 | 小米发布小爱音箱mini,169元;天猫汽车无人贩卖机大楼落地,刷脸可购车试驾
  2. 范成法加工matlab_光学非球面技术原理与加工技术
  3. iOS性能优化 - 网络图片加载优化
  4. 四字节对齐(DWORD-aligned)
  5. ARM 架构(V7,V8),和ARM内核区别,从ARM7,ARM9到Cortex-A7,A8,A9,A12,A15到Cortex-A53,A57
  6. swift添加下拉刷新_React Native自定义下拉刷新组件
  7. 微信小程序1. Forgot to add page route in app.json. 2. Invoking Page() in async task.
  8. 跨设备链路聚合_路由与交换技术(华为设备)第五讲---链路聚合
  9. linux shell运行脚本命令行参数,shell脚本命令行参数简介
  10. Java 读写json格式的文件方法详解
  11. Asciidoctor Maven插件使用
  12. 蓝桥杯真题:单词分析
  13. 2022年信息安全工程师上午真题及答案解析
  14. ECS主动运维事件--让你HOLD住全场 (二)
  15. Android微信代扣sdk无法拉起,微信JS-SDK选择图片遇到的坑
  16. 盘点 4 个开源小游戏
  17. 使用UDP遇到的问题小结
  18. ccf201503-1 ccf 图像旋转-内存限制问题
  19. cad面积累计lisp怎么用_CAD增强的填充面积统计插件LISP源码
  20. 性能测试时那些「难以启齿」的问题-CPU相关

热门文章

  1. Pooling Revisited: Your Receptive Field is Suboptimal
  2. offlineimap读取qq邮箱
  3. Java实现多线程远程投屏并打包可执行文件(从代码到.exe)
  4. 超硬核!程序员10种副业赚钱之道,实现月收入增加20k!
  5. OpenGLES学习(一)图片显示
  6. 计算机论文致谢词范文500字,2021年论文致谢词范文500字(通用5篇)
  7. 实数在计算机中的表示
  8. 水星怎么设置网速最快_水星mw300r怎么提高网速
  9. 使用WPS解决英文不占满一行
  10. 谷歌浏览器最小化后打开黑屏