OsgEarth开发笔记(四):Qt5.15.2在QtCreator集成Osg3.6.3+OsgEarth3.1+OsgQt的vs2019x64版本开发环境搭建

简介: OsgEarth开发笔记(四):Qt5.15.2在QtCreator集成Osg3.6.3+OsgEarth3.1+OsgQt的vs2019x64版本开发环境搭建

前言

  本篇非常麻烦,博主用QtCreator作为IDE,因为Osg3.6.3放弃对osgQt的支持,集成起来比较繁琐。


前提

  基于前面三篇的基础上,才可以进行本篇。


Demo演示:Qt5.15.2+OSG3.6.3+OsgEarth3.1的QtCreator下的msvc2019x64版本

  

Demo运行程序下载

  QQ群:1047134658(点击“文件”搜索“osgEarth v1.0.0”,群内与博文同步更新)


OsgQt下载

  OsgQt地址:https://github.com/openscenegraph/osgQt

  QQ群:1047134658(点击“文件”搜索“osgQt”,群内与博文同步更新)


osgQt编译

步骤一:下载解压

  

步骤二:CMake配置

  

步骤三:CMake配置添加osg环境

  

步骤四:CMake配置添加Qt环境  

  

步骤五:CMake修改CMakeLists文件内容:

  

  还是出现错误:

  

  检查,并未发现错误

  

  继续深入    有一个路径填错了:  

  过了,继续配置:

  


  填入其他Qt路径:

  

  

步骤六:配置通过

  

步骤七:生成成功

  

步骤八:打开工程,进行编译

  

  编译各种问,尝试过多次后放弃,看其他博客是可以的。

  

  (后面的复杂,博主直接修改源码开始移植过去,直接加入工程方式,过程比较艰难,如果能编译好osgQt是最好的,改源码问题较多,需要的可联系博主获取,但是不免费,尊重劳动成果,禁止白嫖)


模块化

  


配置文件

OsgEarthWidget.pri

INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD
QT += opengl
FORMS += \
    $$PWD/OsgWidget.ui
HEADERS += \
    $$PWD/OsgViewerWidget.h \
    $$PWD/OsgWidget.h \
    $$PWD/define.h \
    $$PWD/osgQt/include/osgQOpenGL/Export.h
SOURCES += \
    $$PWD/OsgViewerWidget.cpp \
    $$PWD/OsgWidget.cpp \
    $$PWD/define.cpp
# osg
INCLUDEPATH += $$PWD/osg3.6.3-vs2019/include
DEPENDPATH += $$PWD/osg3.6.3-vs2019/include
LIBS += -L$$PWD/osg3.6.3-vs2019/lib
LIBS += -lOpenThreads \
        -losg \
        -losgAnimation \
        -losgDB \
        -losgFX \
        -losgGA \
        -losgManipulator \
        -losgParticle \
        -losgPresentation \
        -losgShadow \
        -losgText \
        -losgUI \
        -losgUtil \
        -losgViewer \
        -losgVolume \
        -losgWidget \
#        -losgQt \
        -losgSim \
        -losgTerrain
# osgQt
INCLUDEPATH += $$PWD/osgQt/include
DEPENDPATH += $$PWD/osgQt/include
HEADERS += \
    $$PWD/osgQt/include/osgQOpenGL/CullVisitorEx \
    $$PWD/osgQt/include/osgQOpenGL/GraphicsWindowEx \
    $$PWD/osgQt/include/osgQOpenGL/OSGRenderer \
    $$PWD/osgQt/include/osgQOpenGL/RenderStageEx \
    $$PWD/osgQt/include/osgQOpenGL/StateEx \
    $$PWD/osgQt/include/osgQOpenGL/osgQOpenGLWidget \
    $$PWD/osgQt/include/osgQOpenGL/osgQOpenGLWindow
SOURCES += \
    $$PWD/osgQt/include/osgQOpenGL/CullVisitorEx.cpp \
    $$PWD/osgQt/include/osgQOpenGL/GraphicsWindowEx.cpp \
    $$PWD/osgQt/include/osgQOpenGL/OSGRenderer.cpp \
    $$PWD/osgQt/include/osgQOpenGL/RenderStageEx.cpp \
    $$PWD/osgQt/include/osgQOpenGL/StateEx.cpp \
    $$PWD/osgQt/include/osgQOpenGL/osgQOpenGLWidget.cpp \
    $$PWD/osgQt/include/osgQOpenGL/osgQOpenGLWindow.cpp
# osgEarth
INCLUDEPATH += $$PWD/osgearth3.1-vs2019/include
LIBS += -L$$PWD/osgearth3.1-vs2019/lib
LIBS += -losgEarth


Demo源码

osg::ref_ptr<osg::Node> OsgWidget::getEarthSphiere()
{
    osg::ref_ptr<osg::Group> pGroup = new osg::Group;
    osgEarth::initialize();
    const char* styles_css =
    R"(
        p {
            altitude-clamping: terrain-drape;
            render-backface-culling: false;
        }
        p1: p{ fill: #ff3f3f9f; }
        p2: p{ fill: #3fff3f9f; }
        p3: p{ fill: #3f3fff9f; }
        p4: p{ fill: #ff3fff9f; }
        p5: p{ fill: #ffff3f9f; }
    )";
    const char* script_source =
    R"(
        function getStyleClass()
        {
            // Exclude any countries beginning with the letter A:
            if ( feature.properties.name.charAt(0) === 'A' )
                return null;
            // If it starts with the letter C, return an inline style:
            if ( feature.properties.name.charAt(0) == 'C' )
                return '{ _fill: #ffc838; stroke: #8f8838; extrusion-height: 250000; }';
            // Otherwise, return a named style based on some calculations:
            var pop = parseFloat(feature.properties.pop);
            if      ( pop <= 14045470 )  return "p1";
            else if ( pop <= 43410900 )  return "p2";
            else if ( pop <= 97228750 )  return "p3";
            else if ( pop <= 258833000 ) return "p4";
            else                         return "p5";
        }
    )";
    osg::ref_ptr<Map> map = new Map();
    GDALImageLayer* basemap = new GDALImageLayer();
    basemap->setURL("world.tif");
    map->addLayer(basemap);
    // Next we add a layer to provide the feature data.
    OGRFeatureSource* features = new OGRFeatureSource();
    features->setName("vector-data");
    features->setURL("world.shp");
    map->addLayer(features);
    Style style;
    LineSymbol* ls = style.getOrCreateSymbol<LineSymbol>();
    ls->stroke()->color() = Color::Yellow;
    ls->stroke()->width() = 2.0f;
    ls->tessellationSize()->set(100, Units::KILOMETERS);
    FeatureModelLayer* layer = new FeatureModelLayer();
    layer->setFeatureSource(features);
    StyleSheet* styleSheet = new StyleSheet();
    styleSheet->addStyle(style);
    layer->setStyleSheet(styleSheet);
    map->addLayer(layer);
    LayerVector layers;
    map->getLayers(layers);
    for (LayerVector::const_iterator i = layers.begin(); i != layers.end(); ++i)
    {
        Layer* layer = i->get();
        if (layer->getStatus().isError() &&
            layer->getEnabled())
        {
            OE_WARN << layer->getName() << " : " << layer->getStatus().toString() << std::endl;
        }
    }
    MapNode* mapNode = new MapNode(map.get());
    _pViewer->setCameraManipulator(new EarthManipulator());
    pGroup->addChild(mapNode);
    return pGroup.get();
}


工程模板

  osgEarthDemo_工程模板_v1.0.0_搭建好Qt+OSG+EARTH环境显示地球_QtCreaotr下的msvc2019x64版本.rar


相关文章
|
监控 C++ 容器
【qt】MDI多文档界面开发
【qt】MDI多文档界面开发
1016 0
|
C++
C++ Qt开发:QUdpSocket网络通信组件
QUdpSocket是Qt网络编程中一个非常有用的组件,它提供了在UDP协议下进行数据发送和接收的能力。通过简单的方法和信号,可以轻松实现基于UDP的网络通信。不过,需要注意的是,UDP协议本身不保证数据的可靠传输,因此在使用QUdpSocket时,可能需要在应用层实现一些机制来保证数据的完整性和顺序,或者选择在适用的场景下使用UDP协议。
1367 2
|
存储 运维 监控
Qt开发网络嗅探器01
Qt开发网络嗅探器01
关于linux的qt发布(linuxdeployqt)中opengl版本过高的解决
关于linux的qt发布(linuxdeployqt)中opengl版本过高的解决
|
网络协议 容器
Qt开发网络嗅探器03
Qt开发网络嗅探器03
|
开发工具 C++
qt开发技巧与三个问题点
本文介绍了三个Qt开发中的常见问题及其解决方法,并提供了一些实用的开发技巧。
1046 0
|
数据安全/隐私保护 C++ 计算机视觉
Qt(C++)开发一款图片防盗用水印制作小工具
文本水印是一种常用的防盗用手段,可以将文本信息嵌入到图片、视频等文件中,用于识别和证明文件的版权归属。在数字化和网络化的时代,大量的原创作品容易被不法分子盗用或侵犯版权,因此加入文本水印成为了保护原创作品和维护知识产权的必要手段。 通常情况下,文本水印可以包含版权声明、制作者姓名、日期、网址等信息,以帮助识别文件的来源和版权归属。同时,为了增强防盗用效果,文本水印通常会采用字体、颜色、角度等多种组合方式,使得水印难以被删除或篡改,有效地降低了盗用意愿和风险。 开发人员可以使用图像处理技术和编程语言实现文本水印的功能,例如使用Qt的QPainter类进行文本绘制操作,将文本信息嵌入到图片中,
737 1
Qt(C++)开发一款图片防盗用水印制作小工具
|
区块链
【qt】最快的开发界面效率——混合编程3
【qt】最快的开发界面效率——混合编程
356 1

推荐镜像

更多
  • qt