osgQT6

13 篇文章 1 订阅
2 篇文章 0 订阅

1. 说明:

OSG官网的开放源代码,v3.6.5 只支持QT4/5,不支持QT6,需要修改源码及CMakeList.txt

继续搜索 OSG QT6 发现已有大佬改写好了适配 QT6的:

git clone -b  topic/Qt6  https://github.com/DeadParrot/osgQt.git

cmake 编译: debug 版 还是 release 版?

# single configuration 类型的项目配置: #debug
mkdir build; cd $_; cmake .. -DCMAKE_BUILD_TYPE=Debug; make -j8; sudo make install
#Release 默认
mkdir build; cd $_; cmake ..; make -j8; sudo make install

#延伸:multi configuration 类型的项目配置(默认都是Debug)
cmake --build ..  --target install --config Release
cmake --build ..  --target install --config Debug

#若还是没出现d结尾的情况,在CMakeLists.txt中,增加:
set(CMAKE_DEBUG_POSTFIX "d")
set_target_properties(${TARGET_NAME} PROPERTIES DEBUG_POSTFIX "d")

但编译发现还是出问题: 无法链接QT6库

$ mkdir build; cd $_; cmake .. -DCMAKE_BUILD_TYPE=Debug; make -j8;
....
[ 93%] Building CXX object examples/osgviewerQt/CMakeFiles/example_osgviewerQt.dir/osgviewerQt.cpp.o
[100%] Linking CXX executable ../../bin/osgviewerQtd
/usr/bin/ld: 找不到 -lWidgets
/usr/bin/ld: 找不到 -lOpenGLWidgets
collect2: error: ld returned 1 exit status
make[2]: *** [examples/osgviewerQt/CMakeFiles/example_osgviewerQt.dir/build.make:104:bin/osgviewerQtd] 错误 1
make[1]: *** [CMakeFiles/Makefile2:206:examples/osgviewerQt/CMakeFiles/example_osgviewerQt.dir/all] 错误 2
make: *** [Makefile:130:all] 错误 2

解决:

#最外层主 CMakeList.txt +426: 增加一行 link_directories
FIND_PACKAGE(Qt6 COMPONENTS Widgets OpenGL OpenGLWidgets REQUIRED)
link_directories(~/Qt/6.5.1/gcc_64/lib)

最终

$ ll /usr/local/lib64/ | grep osg
lrwxrwxrwx  1 root    root         21 629 16:29 libosgQOpenGLd.so -> libosgQOpenGLd.so.145
lrwxrwxrwx  1 root    root         23 629 16:29 libosgQOpenGLd.so.145 -> libosgQOpenGLd.so.3.6.5
-rw-r--r--  1 root    root    6765472 629 16:29 libosgQOpenGLd.so.3.6.5
lrwxrwxrwx  1 root    root         20 629 11:46 libosgQOpenGL.so -> libosgQOpenGL.so.145
lrwxrwxrwx  1 root    root         22 629 11:46 libosgQOpenGL.so.145 -> libosgQOpenGL.so.3.6.5
-rw-r--r--  1 root    root     303088 629 16:30 libosgQOpenGL.so.3.6.5
lrwxrwxrwx  1 root    root         33 628 18:00 libosgQt.so -> /usr/local/lib64/libosgQOpenGL.so


$ ll /usr/local/lib/ | grep osg
lrwxrwxrwx  1 root root        23 629 15:32 libosgAnimationd.so -> libosgAnimationd.so.161
lrwxrwxrwx  1 root root        25 629 15:32 libosgAnimationd.so.161 -> libosgAnimationd.so.3.6.5
-rw-r--r--  1 root root  12480312 629 15:21 libosgAnimationd.so.3.6.5
lrwxrwxrwx  1 root root        22 628 15:53 libosgAnimation.so -> libosgAnimation.so.161
lrwxrwxrwx  1 root root        24 628 15:53 libosgAnimation.so.161 -> libosgAnimation.so.3.6.5
-rw-r--r--  1 root root   1159248 629 15:04 libosgAnimation.so.3.6.5
lrwxrwxrwx  1 root root        16 629 15:32 libosgDBd.so -> libosgDBd.so.161
lrwxrwxrwx  1 root root        18 629 15:32 libosgDBd.so.161 -> libosgDBd.so.3.6.5
-rw-r--r--  1 root root  19706232 629 15:14 libosgDBd.so.3.6.5
lrwxrwxrwx  1 root root        15 628 18:18 libosgDB.so -> libosgDB.so.161
lrwxrwxrwx  1 root root        17 628 15:53 libosgDB.so.161 -> libosgDB.so.3.6.5
-rw-r--r--  1 root root   1848960 629 14:57 libosgDB.so.3.6.5
lrwxrwxrwx  1 root root        14 629 15:32 libosgd.so -> libosgd.so.161
lrwxrwxrwx  1 root root        16 629 15:32 libosgd.so.161 -> libosgd.so.3.6.5
-rw-r--r--  1 root root  43040448 629 15:14 libosgd.so.3.6.5
lrwxrwxrwx  1 root root        16 629 15:32 libosgFXd.so -> libosgFXd.so.161
lrwxrwxrwx  1 root root        18 629 15:32 libosgFXd.so.161 -> libosgFXd.so.3.6.5
-rw-r--r--  1 root root   4867528 629 15:15 libosgFXd.so.3.6.5
lrwxrwxrwx  1 root root        15 628 15:53 libosgFX.so -> libosgFX.so.161
lrwxrwxrwx  1 root root        17 628 15:53 libosgFX.so.161 -> libosgFX.so.3.6.5
-rw-r--r--  1 root root    309632 629 14:57 libosgFX.so.3.6.5
lrwxrwxrwx  1 root root        16 629 15:32 libosgGAd.so -> libosgGAd.so.161
lrwxrwxrwx  1 root root        18 629 15:32 libosgGAd.so.161 -> libosgGAd.so.3.6.5
-rw-r--r--  1 root root   9549120 629 15:17 libosgGAd.so.3.6.5
lrwxrwxrwx  1 root root        15 628 15:53 libosgGA.so -> libosgGA.so.161
lrwxrwxrwx  1 root root        17 628 15:53 libosgGA.so.161 -> libosgGA.so.3.6.5
-rw-r--r--  1 root root   1100256 629 14:58 libosgGA.so.3.6.5
lrwxrwxrwx  1 root root        25 629 15:32 libosgManipulatord.so -> libosgManipulatord.so.161
lrwxrwxrwx  1 root root        27 629 15:32 libosgManipulatord.so.161 -> libosgManipulatord.so.3.6.5
-rw-r--r--  1 root root   7279480 629 15:21 libosgManipulatord.so.3.6.5
lrwxrwxrwx  1 root root        24 628 15:53 libosgManipulator.so -> libosgManipulator.so.161
lrwxrwxrwx  1 root root        26 628 15:53 libosgManipulator.so.161 -> libosgManipulator.so.3.6.5
-rw-r--r--  1 root root    434288 629 15:04 libosgManipulator.so.3.6.5
lrwxrwxrwx  1 root root        22 629 15:32 libosgParticled.so -> libosgParticled.so.161
lrwxrwxrwx  1 root root        24 629 15:32 libosgParticled.so.161 -> libosgParticled.so.3.6.5
-rw-r--r--  1 root root   8571304 629 15:16 libosgParticled.so.3.6.5
lrwxrwxrwx  1 root root        21 628 15:53 libosgParticle.so -> libosgParticle.so.161
lrwxrwxrwx  1 root root        23 628 15:53 libosgParticle.so.161 -> libosgParticle.so.3.6.5
-rw-r--r--  1 root root    536728 629 14:58 libosgParticle.so.3.6.5
lrwxrwxrwx  1 root root        26 629 15:32 libosgPresentationd.so -> libosgPresentationd.so.161
lrwxrwxrwx  1 root root        28 629 15:32 libosgPresentationd.so.161 -> libosgPresentationd.so.3.6.5
-rw-r--r--  1 root root   7281048 629 15:23 libosgPresentationd.so.3.6.5
lrwxrwxrwx  1 root root        25 628 15:53 libosgPresentation.so -> libosgPresentation.so.161
lrwxrwxrwx  1 root root        27 628 15:53 libosgPresentation.so.161 -> libosgPresentation.so.3.6.5
-rw-r--r--  1 root root    958896 629 15:05 libosgPresentation.so.3.6.5
lrwxrwxrwx  1 root root        20 629 15:32 libosgShadowd.so -> libosgShadowd.so.161
lrwxrwxrwx  1 root root        22 629 15:32 libosgShadowd.so.161 -> libosgShadowd.so.3.6.5
-rw-r--r--  1 root root  10661352 629 15:15 libosgShadowd.so.3.6.5
lrwxrwxrwx  1 root root        19 628 15:53 libosgShadow.so -> libosgShadow.so.161
lrwxrwxrwx  1 root root        21 628 15:53 libosgShadow.so.161 -> libosgShadow.so.3.6.5
-rw-r--r--  1 root root    807232 629 14:58 libosgShadow.so.3.6.5
lrwxrwxrwx  1 root root        17 629 15:32 libosgSimd.so -> libosgSimd.so.161
lrwxrwxrwx  1 root root        19 629 15:32 libosgSimd.so.161 -> libosgSimd.so.3.6.5
-rw-r--r--  1 root root  11321656 629 15:17 libosgSimd.so.3.6.5
lrwxrwxrwx  1 root root        16 628 15:53 libosgSim.so -> libosgSim.so.161
lrwxrwxrwx  1 root root        18 628 15:53 libosgSim.so.161 -> libosgSim.so.3.6.5
-rw-r--r--  1 root root    822816 629 15:00 libosgSim.so.3.6.5
lrwxrwxrwx  1 root root        13 628 15:53 libosg.so -> libosg.so.161
lrwxrwxrwx  1 root root        15 628 15:53 libosg.so.161 -> libosg.so.3.6.5
-rw-r--r--  1 root root   4571888 629 14:56 libosg.so.3.6.5
lrwxrwxrwx  1 root root        21 629 15:32 libosgTerraind.so -> libosgTerraind.so.161
lrwxrwxrwx  1 root root        23 629 15:32 libosgTerraind.so.161 -> libosgTerraind.so.3.6.5
-rw-r--r--  1 root root   6004064 629 15:15 libosgTerraind.so.3.6.5
lrwxrwxrwx  1 root root        20 628 15:53 libosgTerrain.so -> libosgTerrain.so.161
lrwxrwxrwx  1 root root        22 628 15:53 libosgTerrain.so.161 -> libosgTerrain.so.3.6.5
-rw-r--r--  1 root root    524232 629 14:57 libosgTerrain.so.3.6.5
lrwxrwxrwx  1 root root        18 629 15:32 libosgTextd.so -> libosgTextd.so.161
lrwxrwxrwx  1 root root        20 629 15:32 libosgTextd.so.161 -> libosgTextd.so.3.6.5
-rw-r--r--  1 root root   7379672 629 15:15 libosgTextd.so.3.6.5
lrwxrwxrwx  1 root root        17 628 15:53 libosgText.so -> libosgText.so.161
lrwxrwxrwx  1 root root        19 628 15:53 libosgText.so.161 -> libosgText.so.3.6.5
-rw-r--r--  1 root root    560752 629 14:57 libosgText.so.3.6.5
lrwxrwxrwx  1 root root        16 629 15:32 libosgUId.so -> libosgUId.so.161
lrwxrwxrwx  1 root root        18 629 15:32 libosgUId.so.161 -> libosgUId.so.3.6.5
-rw-r--r--  1 root root   6161464 629 15:21 libosgUId.so.3.6.5
lrwxrwxrwx  1 root root        15 628 15:53 libosgUI.so -> libosgUI.so.161
lrwxrwxrwx  1 root root        17 628 15:53 libosgUI.so.161 -> libosgUI.so.3.6.5
-rw-r--r--  1 root root    456760 629 15:04 libosgUI.so.3.6.5
lrwxrwxrwx  1 root root        18 629 15:32 libosgUtild.so -> libosgUtild.so.161
lrwxrwxrwx  1 root root        20 629 15:32 libosgUtild.so.161 -> libosgUtild.so.3.6.5
-rw-r--r--  1 root root  31976568 629 15:14 libosgUtild.so.3.6.5
lrwxrwxrwx  1 root root        17 628 15:53 libosgUtil.so -> libosgUtil.so.161
lrwxrwxrwx  1 root root        19 628 15:53 libosgUtil.so.161 -> libosgUtil.so.3.6.5
-rw-r--r--  1 root root   2786672 629 14:56 libosgUtil.so.3.6.5
lrwxrwxrwx  1 root root        20 629 15:32 libosgViewerd.so -> libosgViewerd.so.161
lrwxrwxrwx  1 root root        22 629 15:32 libosgViewerd.so.161 -> libosgViewerd.so.3.6.5
-rw-r--r--  1 root root  14170328 629 15:20 libosgViewerd.so.3.6.5
lrwxrwxrwx  1 root root        19 628 15:53 libosgViewer.so -> libosgViewer.so.161
lrwxrwxrwx  1 root root        21 628 15:53 libosgViewer.so.161 -> libosgViewer.so.3.6.5
-rw-r--r--  1 root root   1534848 629 15:01 libosgViewer.so.3.6.5
lrwxrwxrwx  1 root root        20 629 15:32 libosgVolumed.so -> libosgVolumed.so.161
lrwxrwxrwx  1 root root        22 629 15:32 libosgVolumed.so.161 -> libosgVolumed.so.3.6.5
-rw-r--r--  1 root root   6716560 629 15:19 libosgVolumed.so.3.6.5
lrwxrwxrwx  1 root root        19 628 15:53 libosgVolume.so -> libosgVolume.so.161
lrwxrwxrwx  1 root root        21 628 15:53 libosgVolume.so.161 -> libosgVolume.so.3.6.5
-rw-r--r--  1 root root    726088 629 15:00 libosgVolume.so.3.6.5
lrwxrwxrwx  1 root root        20 629 15:32 libosgWidgetd.so -> libosgWidgetd.so.161
lrwxrwxrwx  1 root root        22 629 15:32 libosgWidgetd.so.161 -> libosgWidgetd.so.3.6.5
-rw-r--r--  1 root root   7577856 629 15:22 libosgWidgetd.so.3.6.5
lrwxrwxrwx  1 root root        19 628 15:53 libosgWidget.so -> libosgWidget.so.161
lrwxrwxrwx  1 root root        21 628 15:53 libosgWidget.so.161 -> libosgWidget.so.3.6.5
-rw-r--r--  1 root root    692016 629 15:04 libosgWidget.so.3.6.5
drwxr-xr-x  2 root root     12288 629 15:32 osgPlugins-3.6.5/


$ ll /usr/local/lib/ | grep OpenThreads
lrwxrwxrwx  1 root root        21 629 15:32 libOpenThreadsd.so -> libOpenThreadsd.so.21
lrwxrwxrwx  1 root root        24 629 15:32 libOpenThreadsd.so.21 -> libOpenThreadsd.so.3.3.1
-rw-r--r--  1 root root    218336 629 15:13 libOpenThreadsd.so.3.3.1
lrwxrwxrwx  1 root root        20 628 15:53 libOpenThreads.so -> libOpenThreads.so.21
lrwxrwxrwx  1 root root        23 628 15:53 libOpenThreads.so.21 -> libOpenThreads.so.3.3.1
-rw-r--r--  1 root root     53296 629 14:55 libOpenThreads.so.3.3.1

2. OSG-QT Demo

//CMakeLists.txt
# 添加OSG支持
SET(OSG_DEBUG_POSTFIX "d" CACHE STRING "use postfix to link with osg with debug")
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS OpenGL OpenGLWidgets)
find_package(OpenSceneGraph REQUIRED osg osgGA osgViewer osgUtil osgShadow osgFX osgDB osgUtil)
include_directories(include ${OPENSCENEGRAPH_INCLUDE_DIR})
link_directories(${CMAKE_LIBRARY_PATH} ${OPENSCENEGRAPH_LIB_DIR})
set(osgQOpenGL /usr/local/lib64)
set(OSGLIB
    Qt6::OpenGLWidgets
    osgQOpenGL
    osg osgGA osgViewer osgUtil osgShadow osgFX osgDB osgUtil
)
# 下面一行只需增加 ${OSGLIB}
target_link_libraries(Demo PRIVATE Qt${QT_VERSION_MAJOR}::Widgets ${OSGLIB})
// Demo.pro
include(osgqt.pri)

// osgqt.pri
QT          += opengl openglwidgets
INCLUDEPATH += /usr/local/include
DEPENDPATH  += /usr/local/include

CONFIG(release, debug|release) {
    LIBS += -L/usr/local/lib64 -losgQOpenGL
    LIBS += -L/usr/local/lib -lOpenThreads -losgDB -losgViewer -losgWidget -losg -losgUtil -losgGA -losgText
} else {
    LIBS += -L/usr/local/lib64 -losgQOpenGLd
    LIBS += -L/usr/local/lib -lOpenThreadsd -losgDBd -losgViewerd losgWidgetd -losgd -losgUtild -losgGAd -losgTextd
}
// mainwindow.h
public slots:
    void initOsg();
// mainwindow.cpp
#include <osgQOpenGL/osgQOpenGLWidget>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osgUtil/Optimizer>
#include <osgGA/TrackballManipulator>

MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    ui->pOsgW->setAttribute(Qt::WA_AlwaysStackOnTop);
    setCentralWidget(ui->pOsgW);
    connect(ui->pOsgW, &osgQOpenGLWidget::initialized, this, &MainWindow::initOsg);
}

void MainWindow::initOsg()
{
    osgViewer::Viewer *pViewer = ui->pOsgW->getOsgViewer();
    pViewer->setCameraManipulator(new osgGA::TrackballManipulator());
    osg::Node *pNode = osgDB::readNodeFile("cow.osg");
    osgUtil::Optimizer optimizer;
    optimizer.optimize(pNode);
    pViewer->setSceneData(pNode);
}
// mainwindow.ui
拖拽一个 OpenGL Widget,右键提升为这个:
osgQOpenGLWidget  #类
osgQOpenGL/osgQOpenGLWidget #头文件路径

3. 报错:

Error reading file cow.osg: file not found (cow.osg文件需要从官网下载 OpenSceneGraph-Data-3.4.0.zip )

Error reading file Images/reflect.rgb: file not found (可以忽略)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值