osgEarth学习笔记3-第二个Osg QT程序

原文链接

打开QT Creator,新建一个窗口项目。

QT版本如下:

修改pro文件

QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
    main.cpp \
    mainwindow.cpp
HEADERS += \
    mainwindow.h
FORMS += \
    mainwindow.ui
INCLUDEPATH += "D:\coding\osgearth\osgearth-vcpkg-installed\installed\x86-windows\include"
INCLUDEPATH += "D:\coding\osgearth\osgQt-master\include"
INCLUDEPATH += "D:\coding\osgearth\osgQt-master\build-win32\src"
INCLUDEPATH += "D:\coding\osgearth\osgQt-master\build-win32\include"
INCLUDEPATH += "D:\coding\osgearth\osgQt-master\build-win32\include"
LIBS += -L"D:\coding\osgearth\osgearth-vcpkg-installed\installed\x86-windows\lib" -losg -losgUtil -losgViewer  -losgGA  -losgDB  -lOpenThreads -lopengl32
LIBS += -L"D:\coding\osgearth\osgQt-master\build-win32\lib" -losgQOpenGL
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

 修改main.cpp文件

#include "mainwindow.h"

#include <QApplication>
#include <osgQOpenGL/osgQOpenGLWidget>
#include <osgDB/ReadFile>
#include <osgUtil/Optimizer>
#include <osg/CoordinateSystemNode>
#include <osg/Switch>
#include <osg/Types>
#include <osgText/Text>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgGA/KeySwitchMatrixManipulator>
#include <osgGA/StateSetManipulator>
#include <osgGA/AnimationPathManipulator>
#include <osgGA/TerrainManipulator>
#include <osgGA/SphericalManipulator>
#include <osgGA/Device>
#include <QSurfaceFormat>
#include <iostream>
using std::cout;
using std::endl;
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    osg::ArgumentParser arguments(&argc, argv);
    osgQOpenGLWidget widget(&arguments);
    QObject::connect(&widget, &osgQOpenGLWidget::initialized,[&widget]
        {
            osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
            keyswitchManipulator->addMatrixManipulator('1', "Trackball", new osgGA::TrackballManipulator());//must has add one at least
            widget.getOsgViewer()->setCameraManipulator(keyswitchManipulator.get());//must has
            // load the data
            osg::Node* nodePtr = osgDB::readNodeFile("D:/coding/osgearth/build-osgQtTest1-Desktop_Qt_5_14_2_MSVC2017_32bit-Release/release/cow.osgt") ;
            if(!nodePtr)
            {
                std::cout << "No data loaded" << std::endl;
                return 1;
            }
            widget.getOsgViewer()->setSceneData(nodePtr);
            return 0;
        });

    MainWindow w;
    w.setCentralWidget(&widget);
    w.show();
    return a.exec();
}

 以Release模式编译,拷贝上个笔记提到的dll到exe目录,注意要调用windeployqt解决部分qt依赖项。执行程序。

相关推荐

最近更新

  1. TCP协议是安全的吗?

    2024-03-19 13:24:04       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-19 13:24:04       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-19 13:24:04       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-19 13:24:04       20 阅读

热门阅读

  1. 【DevOps基础篇】Agile中重要的10个衡量指标

    2024-03-19 13:24:04       20 阅读
  2. [日报] Ribbon、Eureka、Nginx、负载均衡

    2024-03-19 13:24:04       19 阅读
  3. OpenCV-图像通道处理

    2024-03-19 13:24:04       20 阅读
  4. 【NLP7-使用RNN模型构建人名分类器】

    2024-03-19 13:24:04       18 阅读
  5. CentOS 同时安装多个版本Python3

    2024-03-19 13:24:04       19 阅读
  6. Python 的 typing 模块:类型提示的利器

    2024-03-19 13:24:04       17 阅读
  7. Stream流

    Stream流

    2024-03-19 13:24:04      16 阅读
  8. docker菜鸟教程

    2024-03-19 13:24:04       17 阅读