当前位置: 首页 > article >正文

QT+OSG+osg-earth显示一个球

目录

1、环境配置

2、在QT  Creator导入相关的库

3、代码部分

4、运行过程中的问题

5、相关参考


重要衔接:QT+OSG显示一个三维模型-CSDN博客

1、环境配置

 系统:windows10系统

QT:版本5.15.2        编译器:MSVC2019_64bit        编辑器:QT  Creator

OSG版本:3.7.0   64位      为MSVC环境下编译

osgQt:为第三方编译的库,OSG因为版本不同已经不提供osgQt的封装。

osg-earth版本: 3.6.0

2、在QT  Creator导入相关的库

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/osg370MSVC2019_64bit/OSG/lib/ -losg  -losgDB -losgUtil  -losgViewer  -losgGA   -losgWidget   -lOpenThreads
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/osg370MSVC2019_64bit/OSG/lib/ -losgd  -losgDBd -losgUtild  -losgViewerd  -losgGAd  -losgWidgetd -lOpenThreadsd
else:unix: LIBS += -L$$PWD/osg370MSVC2019_64bit/OSG/lib/ -losg  -losgDB -losgUtil  -losgViewer  -losgGA  -losgWidget   -lOpenThreads

INCLUDEPATH += $$PWD/osg370MSVC2019_64bit/OSG/include
DEPENDPATH += $$PWD/osg370MSVC2019_64bit/OSG/include



win32:CONFIG(release, debug|release): LIBS += -L$$PWD/osgQtVC2019_64bit/vs2019_x64_osgQt/osgQt/lib/ -losgQOpenGL
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/osgQtVC2019_64bit/vs2019_x64_osgQt/osgQt/lib/ -losgQOpenGLd
else:unix: LIBS += -L$$PWD/osgQtVC2019_64bit/vs2019_x64_osgQt/osgQt/lib/ -losgQOpenGL

INCLUDEPATH += $$PWD/osgQtVC2019_64bit/vs2019_x64_osgQt/osgQt/include
DEPENDPATH += $$PWD/osgQtVC2019_64bit/vs2019_x64_osgQt/osgQt/include



win32:CONFIG(release, debug|release): LIBS += -L$$PWD/vs2019_x64_osgearth_3.6.0/OSGEARTH/lib/ -losgEarth
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/vs2019_x64_osgearth_3.6.0/OSGEARTH/lib/ -losgEarthd
else:unix: LIBS += -L$$PWD/vs2019_x64_osgearth_3.6.0/OSGEARTH/lib/ -losgEarth

INCLUDEPATH += $$PWD/vs2019_x64_osgearth_3.6.0/OSGEARTH/include
DEPENDPATH += $$PWD/vs2019_x64_osgearth_3.6.0/OSGEARTH/include



win32:CONFIG(release, debug|release): LIBS += -L$$PWD/vs2019_x64_osgearth_3.6.0/OSGEARTH/lib/ -losgEarth
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/vs2019_x64_osgearth_3.6.0/OSGEARTH/lib/ -losgEarthd
else:unix: LIBS += -L$$PWD/vs2019_x64_osgearth_3.6.0/OSGEARTH/lib/ -losgEarth

INCLUDEPATH += $$PWD/vs2019_x64_osgearth_3.6.0/OSGEARTH/include
DEPENDPATH += $$PWD/vs2019_x64_osgearth_3.6.0/OSGEARTH/include

一个是osg的库,一个是osgQt的库,一个是osg-earth的库。

3、代码部分

main.cpp

#include <QCoreApplication>
#include <QApplication>
#include <QDir>
//#include "osgshowwidget.h"
#include <osgEarth/Map>
#include <osgEarth/MapNode>
#include <osgEarth/EarthManipulator>
#include <osgEarth/MapNode>
#include <osgEarth/TMS>
#include <osgEarth/EarthManipulator>
#include <osg/ArgumentParser>
#include <osgViewer/Viewer>

#include <QWidget>
#include <osgViewer/Viewer>
#include <osg/Node>
#include <osgDB/ReadFile>
#include <osgGA/TrackballManipulator>
#include<osgGA/FlightManipulator>
#include <osgViewer/View>
#include <osgQOpenGL/osgQOpenGLWidget>

#include <osg/Timer>
#include <osg/ArgumentParser>
#include <osgGA/CameraManipulator>

int main(int argc, char *argv[])
{
        QApplication a(argc, argv);

//    // 获取可执行文件的目录
        QString exeDir = QCoreApplication::applicationDirPath();
        QDir::setCurrent(exeDir);

   //osgShowWidget w;
  //  w.show();


    // 初始化osgViewer
    // 初始化osgEarth
    osgEarth::initialize();
    osg::ArgumentParser args(&argc, argv);

    // 创建Viewer实例
    osgViewer::Viewer viewer(args);

    // 使用相对于exe的相对路径来构建.earth文件的完整路径
    QString relativeEarthFilePath = "Maps/ocean.earth";  // 请替换为你实际的.earth文件相对路径
    QString earthFilePath = exeDir + "/" + relativeEarthFilePath;

    // 请替换为你实际的.earth文件路径
    osg::ref_ptr<osg::Node> earthNode = osgDB::readNodeFile(earthFilePath.toStdString());

    if (!earthNode) {
        std::cerr << "Failed to load .earth file: " << earthFilePath.toStdString() << std::endl;
        return -1;  // 如果加载失败,返回错误码
    }

    // 设置场景数据为加载的.earth文件
    viewer.setSceneData(earthNode.get());

    // 设置地球操控器
    viewer.setCameraManipulator(new osgEarth::Util::EarthManipulator(args));

    // 运行Viewer
    return viewer.run();



    //return a.exec();
}

运行结果:

4、运行过程中的问题

osg-earth是基于osg上的封装,osg又是基于opengl上的封装所以需要底层依赖库:

所以想要运行exe,需要把gdal381下的所有的dll文件都拷贝到exe可执行文件下,还有osg下的所有的dll文件,还有osg-earth下的所有的dll文件,包括

这个文件夹下的所有的dll文件。

由于需要的底层依赖库需要

这个是release模式的,在debug模式下就无法运行。会报错

由于我使用osg以及相关的库都是用的别人编译好的,我自己编译不成功,所以只能这样了。

5、相关参考

OSG基础教程(二)osg嵌入Qt窗口(兼容Qt5)_osg qt-CSDN博客


 

VS2019 编译最新版 OSG+ OSGEarth + OSGQt 详细教程_osgearth 2019-CSDN博客

可以在这个博主这里下载编译好的库,我使用就是他编译好的

GitHub - gwaldron/osgearth: 3D Maps for OpenSceneGraph / C++14


http://www.kler.cn/news/289978.html

相关文章:

  • 智能电网中巡检机器人的信息安全技术应用
  • VMware Workstation 17.6 Pro 发布下载,新增功能概览
  • AI学习记录 - 对抗性神经网络
  • 企业架构的概念及发展历程简述(附TOGAF架构理论学习资料下载链接)
  • macos安装ArgoCD
  • linux nc
  • 【Altium Designer脚本开发】——PCB平面绕组线圈 V1.4
  • 河南建筑智能化设计专项资质延期流程说明
  • 力扣2503.矩阵查询可获得的最大分数
  • 超声波清洗机有没有平价又好用的推荐?高性价比的眼镜清洗机推荐
  • 百度飞将 paddle ,实现贝叶斯神经网络 bayesue neure network bnn,aistudio公开项目 复现效果不好
  • 语言质量评估对欧洲游戏推广的重要性
  • 阿凡达2.0直播模式来了,数字人直播行业迎来浴火重生!
  • django企业开发实战-学习小结
  • 活动系统开发之采用设计模式与非设计模式的区别-数据库设计及代码设计
  • LeetCode37 解数独
  • 【Steam游戏星露谷物语添加Mod步骤】
  • css中calc
  • 【陪诊系统-H5客户端】订单状态进度条
  • 如果已经提交,重新添加gitignore文件,会忽略么
  • 【QT】学习笔记:枚举桌面窗口句柄
  • 代码随想录算法训练营第35天|背包问题基础、46. 携带研究材料(01背包二维解法)(01背包一维解法)(acm)、416. 分割等和子集
  • 解决Vue npm 淘宝镜像证书过期问题
  • Blazor项目中建立WebApi
  • C++使用MyStack和MyQueue封装栈和队列
  • Chrome 浏览器插件获取网页 window 对象(方案一)
  • pip切换清华源
  • 数据结构二叉树——堆
  • Scott Brinker:Martech中的AI会让买家体验更好还是更糟?这取决于…….
  • Unity版本升级2022 Gradle 升级7.x版本调整