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依赖项。执行程序。

  • 8
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值