OSGQt編譯安裝
效果演示

1、準備作業
-
最新版的osg中不附帶osgQt原始碼,所以需要單獨下載編譯
-
在編譯osgQt前需要先編譯osg原始碼,osg編譯安裝看這里
-
編譯osgQt的環境與之前編譯osg原始碼一樣
2、osgQt下載
-
github
-
可使用git下載:
git clone [email protected]:openscenegraph/osgQt.git
3、配置環境變數
-
osg:編譯好后按OSG編譯安裝-MSVC中方式配置環境變數
-
msvc2017_64:由于這里使用msvc64編譯,所以需要添加相應的環境變數
-
打開環境變數視窗
-
加入如下路徑(需要修改為自己的Qt安裝路徑)
D:\Qt\5.14.2\msvc2017_64\bin D:\Qt\5.14.2\msvc2017_64\lib

-
-
環境變數配置后重啟電腦使環境變數生效
4、CMake編譯
-
具體步驟和編譯osg差不多
-
將CMakelists.txt拖入CMake中,設定好編譯后的路徑build

-
點擊Configure,這里的選擇必須與osg編譯一樣(如果沒配置環境變數,則這一步會報錯,顯示找不到
Qt5Config.cmake等檔案)

-
修改CMAKE_INSTALL_PREFIX

-
點擊Configure -> Generate -> Open Project
5、Visual Studio編譯
-
后續步驟就和編譯osg一樣,編譯好osgQt后,有如下4個檔案夾,將檔案夾中內容復制到osg安裝路徑下對應檔案夾下即可(編譯后會有兩個lib)


6、Qt Demo
-
pro檔案添加
INCLUDEPATH += D:/OSG/install/include DEPENDPATH += D:/OSG/install/include ? win32:CONFIG(release, debug|release): LIBS += -LD:/OSG/install/lib/ -losgQOpenGL else:win32:CONFIG(debug, debug|release): LIBS += -LD:/OSG/install/lib/ -losgQOpenGLd ? win32:CONFIG(release, debug|release): LIBS += -LD:/OSG/install/lib/ -losgViewer else:win32:CONFIG(debug, debug|release): LIBS += -LD:/OSG/install/lib/ -losgViewerd ? win32:CONFIG(release, debug|release): LIBS += -LD:/OSG/install/lib/ -losgGA else:win32:CONFIG(debug, debug|release): LIBS += -LD:/OSG/install/lib/ -losgGAd ? ? win32:CONFIG(release, debug|release): LIBS += -LD:/OSG/install/lib/ -losgDB else:win32:CONFIG(debug, debug|release): LIBS += -LD:/OSG/install/lib/ -losgDBd ? win32:CONFIG(release, debug|release): LIBS += -LD:/OSG/install/lib/ -losg else:win32:CONFIG(debug, debug|release): LIBS += -LD:/OSG/install/lib/ -losgd
-
ui檔案添加一個button,一個widget

-
widget.h
#ifndef WIDGET_H #define WIDGET_H ? #include <QWidget> #include <osgQOpenGL/osgQOpenGLWidget> ? QT_BEGIN_NAMESPACE namespace Ui { class Widget; } QT_END_NAMESPACE ? class Widget : public QWidget { Q_OBJECT ? public: Widget(QWidget *parent = nullptr); ~Widget(); ? protected slots: void initOSG(); ? private slots: void on_pushButton_clicked(); ? private: Ui::Widget *ui; ? osgQOpenGLWidget* osgWidget; QString m_fileName; }; #endif // WIDGET_H
-
widget.cpp
#include "widget.h" #include "ui_widget.h" #include <osgViewer/Viewer> #include <osg/Node> #include <osgDB/ReadFile> #include <osgGA/TrackballManipulator> ? Widget::Widget(QWidget *parent) : QWidget(parent) , ui(new Ui::Widget) { ui->setupUi(this); ? osgWidget = new osgQOpenGLWidget(ui->widget); // 指定osg視窗顯示位置 osgWidget->setGeometry(ui->widget->geometry()); // 指定osg視窗顯示大小 m_fileName = "D:/OSG/OpenSceneGraph-Data/avatar.osg"; // 顯示模型路徑 ? connect(osgWidget, SIGNAL(initialized()), this, SLOT(initOSG())); } ? Widget::~Widget() { delete ui; if(osgWidget != NULL) { delete osgWidget; } } ? void Widget::initOSG() { osgViewer::Viewer* pViewer = osgWidget->getOsgViewer(); pViewer->setCameraManipulator(new osgGA::TrackballManipulator); osg::Node* node = osgDB::readNodeFile(m_fileName.toStdString()); pViewer->setSceneData(node); } ? void Widget::on_pushButton_clicked() { m_fileName = "D:/OSG/OpenSceneGraph-Data/bignathan.osg"; initOSG(); }
7、編譯好的庫
鏈接:https://pan.baidu.com/s/1UfNbJ0fUAzKfe3XrWNVTDA
提取碼:66tf
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/288570.html
標籤:其他
