OSG、OSGEarth使用

一、概述

1、下载地址
osg官网: :http://www.openscenegraph.org/
osg    : http://www.openscenegraph.org/downloads/stable_releases/
osg Github :https://github.com/openscenegraph/OpenSceneGraph
3rdParty  : https://download.osgvisual.org/
osgEarth  : http://www.openscenegraph.org/index.php/download-section/stable-releases
2、学习大神
osgChina站长文集
osgEarth的Rex引擎原理分析
大神编译好的各种版本的库
3、教学视频
塔库咪的osg72和osgEarth35讲
osgEarth 35讲教学视频
OSG的B站小讲堂

二、编译

1、osg编译
osg编译(修改makefile qt)
编译安装OpenSceneGraph(OSG)教程
osgEarth编译配置(含OSG)
osgQOpenGL的编译与使用
osg mingw编译
osg mingw编译带版本号
osg qt mingw编译

osgEarth编译时可参考的配置路径

//修改CMakeLists.txt直接加入配置
#--------------------------------------------------------------------------------------------
SET(LIBZIP_LIBRARY "E:/OSGEarth/3rdForMe/libzip-1.7.3/install/lib/zip.lib")
SET(LIBZIP_CONF_INCLUDE_DIR "E:/OSGEarth/3rdForMe/libzip-1.7.3/install/include")
SET(GLEW_INCLUDE_DIRS "E:/OSGEarth/3rdForMe/glew-2.1.0/install/include")
SET(GLEW_LIBRARIES "E:/OSGEarth/3rdForMe/glew-2.1.0/install/lib/glew32.lib")
SET(GLEW_INCLUDE_DIR "E:/OSGEarth/3rdForMe/glew-2.1.0/install/include")
SET(GLEW_LIBRARY "E:/OSGEarth/3rdForMe/glew-2.1.0/install/lib/glew32.lib")

SET(PROTOBUF_INCLUDE_DIR "E:/OSGEarth/3rdForMe/protobuf-3.15.5/install/include")
SET(PROTOBUF_LIBRARY_DEBUG "E:/OSGEarth/3rdForMe/protobuf-3.15.5/install/lib/libprotobufd.lib")
SET(PROTOBUF_LIBRARY_RELEASE "E:/OSGEarth/3rdForMe/protobuf-3.15.5/install/lib/libprotobuf.lib")
SET(PROTOBUF_LITE_LIBRARY "E:/OSGEarth/3rdForMe/protobuf-3.15.5/install/lib/libprotobuf-lite.lib")
SET(PROTOBUF_LITE_LIBRARY_DEBUG "E:/OSGEarth/3rdForMe/protobuf-3.15.5/install/lib/libprotobuf-lited.lib")
set(Protobuf_PROTOC_EXECUTABLE "E:/OSGEarth/3rdForMe/protobuf-3.15.5/install/bin/protoc.exe")
SET(PROTOBUF_PROTOC_LIBRARY_DEBUG "E:/OSGEarth/3rdForMe/protobuf-3.15.5/install/lib/libprotocd.lib")
SET(PROTOBUF_PROTOC_LIBRARY_RELEASE "E:/OSGEarth/3rdForMe/protobuf-3.15.5/install/lib/libprotoc.lib")

2、各种编译问题的解决
(1)ZERO_CHECK错误

  • 问题:在osg编译过程中,没有生成Release版,切换成release,生成INSTALL时报:“ZERO_CHECK 错误:
    未能完成操作。未指定的错误”。
  • 解决:
    ①先把ZERO_CHECK.vcxproj 文件剪切到其他地方
    ②打开OpenSceneGraph.sln, 此时ZERO_CHECK会显示无法加载
    ③把ZERO_CHECK.vcxproj拷贝回原地方 4,右键点击Ilmlmf,----》重新加载(找到路径)或手动加载
    (2)MVT不是osgEarth的成员
    原因:MVT头文件中有条件,没满足所以没定义,主要是cmake时protobuf设置不对
    解决:像图中不用DLL,同时注意是src路径
    在这里插入图片描述
    在这里插入图片描述
    最终通过直接set设置路径

3、自己编译的库放到3rdparty
如把编译后libzip头文件放到G:\OSGCore\Bulid\OpenSceneGraphic\3rdParty\include\libzip下,.lib放到lib文件夹中,.dll文件放到bin文件夹中。
4、cmake下的findpackage对应的cmake文件
FindProtobuf.cmake FindGlew.cmake
5、glew not found
cmake找不到glew的问题
最终直接set设置
5、protobuf编译问题
直接set设置路径,后来又报:

出现:error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MTd_StaticDebug”不匹配
解决:将osgEarthCore的改成MTD、MT,又报出一大堆错,还是改protobuf的吧,于是重新编译protobuf,将protobuf改成MD、MDd。(工程属性 -》c/c+ -》代码生成 -》运行库 )

error LNK2038: 检测到“_ITERATOR_DEBUG_LEVEL”的不匹配项: 值“2”不匹配值“0
解决:osgearth的release中用了protobufd.lib库导致。“工程属性->链接器->输入->附加依赖项” 中改为protobuf.lib
6、运行osgearth_viewer.exe报 “无法定位序数4540于动态链接库ssleay32.dll”
解决:将ssleay32.dll、libeay32.dll、libeay32.lib、libpng16.dll拷贝到bin目录

三、验证

1、命令行验证

osgviewer cow.osg
osgearth_viewer simple.earth

2、Qt 控制台程序

//osg
int main()
{
	osgViewer::Viewer viewer;
	viewer.setSceneData(osgDB::readNodeFile("cow.osg"));
	return viewer.run();
}
//osgearth
int main()
{
	osgViewer::Viewer viewer;
	viewer.setSceneData(osgDB::readNodeFile("simple.earth"));
	return viewer.run();
}

运行“simple.earth”报错:
Error reading file simple.earth: read error (Could not find plugin to read objects from file “simple.earth”.)
好像就是缺少插件的意思,然后看了前面的.bin文件,然后里面有一个名为osgPlugins-3.4.0的文件夹,猜想会不会是因为缺少这个的原因,然后把这个文件夹直接复制到了我项目的构建目录build-test001-Desktop_Qt_5_7_1_MSVC2015_64bit-Debug(根据自己的设置而定)中。

三、使用

osg嵌入Qt的五种方式
osgEarth嵌入qt的实现方式
osgEarth嵌入Qt之osgQt::GraphicsWindowQt
osgEarth嵌入Qt之QOpenGLWidget、osgViewer
osg3.6之后版本嵌入qt不能用osgQt(好)
osgEarth三维可视化系列文章

问题记录:

//#include <osgEarth/GLUtils>与#include <QOpenGLWidget>冲突,报错如下
D:\Qt\Qt5.12.3\5.12.3\msvc2017\include\QtGui\qopenglext.h:476: error: C2226: 语法错误: 意外的“uintptr_t”类型
//qopenglext.h
#include <stddef.h>
typedef ptrdiff_t GLsizeiptr;
typedef ptrdiff_t GLintptr;

临时解决方法:注释掉:#include <osgEarth/GLUtils>

1、osg

2、osgEarth

笔记1: 自制osgEarth球的earth文件
笔记2: 加入Qt

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值