首页 > 其他分享 >osgQt使用(osgQOpenGL版本)OSG3.6.5 VS2019 Qt5.15.2 CMAKE3.24

osgQt使用(osgQOpenGL版本)OSG3.6.5 VS2019 Qt5.15.2 CMAKE3.24

时间:2023-01-03 15:47:23浏览次数:59  
标签:Qt5.15 osgQt lib VS2019 osg365Vs2019x64 Widget osgENV include osg365

 

Qt5.15.2新建QWidget工程

QT新建的去qmake工程的.pro文件设置

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++17

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp \
    widget.cpp

HEADERS += \
    widget.h

Osg_qt          =  G:/osgENV/osgQt
INCLUDEPATH     += $${Osg_qt}/include \
    G:/osgENV/osg365Vs2019x64/osg365/include
CONFIG(debug, debug|release){
    LIBS += $${Osg_qt}/lib/osgQOpenGLd.lib \
        G:/osgENV/osg365Vs2019x64/osg365/lib/osgd.lib \
        G:/osgENV/osg365Vs2019x64/osg365/lib/osgViewerd.lib \
        G:/osgENV/osg365Vs2019x64/osg365/lib/osgDBd.lib \
        G:/osgENV/osg365Vs2019x64/osg365/lib/osgUtild.lib \
        G:/osgENV/osg365Vs2019x64/osg365/lib/OpenThreadsd.lib \
        G:/osgENV/osg365Vs2019x64/osg365/lib/osgGAd.lib \
}else
{
    LIBS += $${Osg_qt}/lib/osgQOpenGL.lib \
        G:/osgENV/osg365Vs2019x64/osg365/lib/osg.lib \
        G:/osgENV/osg365Vs2019x64/osg365/lib/osgViewer.lib \
        G:/osgENV/osg365Vs2019x64/osg365/lib/osgDB.lib \
        G:/osgENV/osg365Vs2019x64/osg365/lib/osgUtil.lib \
        G:/osgENV/osg365Vs2019x64/osg365/lib/OpenThreads.lib \
        G:/osgENV/osg365Vs2019x64/osg365/lib/osgGA.lib \
}

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

widget.h文件

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <osgQOpenGL/osgQOpenGLWidget>
#include <osgGA/TrackballManipulator>
#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osg/Texture2D>


class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
private:
    osgQOpenGLWidget* _pOsgWidget;
    osg::ref_ptr<osgViewer::Viewer> _viewer;

signals:
private slots:
void initOsg();
void initOsgWindow();
};
#endif // WIDGET_H

widget.cpp文件

#include "widget.h"
#include <QHBoxLayout>
#include <osgDB/ReadFile>
#include <osgDB/Options>
#include <osgUtil/Optimizer>
using namespace osgDB;
Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
//    //方式一
//    resize(800, 600);
//    QHBoxLayout *pLayout = new QHBoxLayout(this);
//    pLayout->setMargin(0);
//    osgQOpenGLWidget *pOsgW = new osgQOpenGLWidget;
//    pLayout->addWidget(pOsgW);
//    connect(pOsgW, SIGNAL(initialized()), this, SLOT(initOsg()));
    //方式二
    _pOsgWidget = new osgQOpenGLWidget(this);
    connect(_pOsgWidget, SIGNAL(initialized()), this, SLOT(initOsgWindow()));
    QHBoxLayout * layout = new QHBoxLayout;
    setLayout(layout);
    layout->addWidget(_pOsgWidget);
}

Widget::~Widget()
{
}

void Widget::initOsg()
{
    osgViewer::Viewer *pViewer = ((osgQOpenGLWidget *)sender())->getOsgViewer();
    pViewer->setCameraManipulator(new osgGA::TrackballManipulator());
    osg::Node *pNode = osgDB::readNodeFile("G:/osgENV/OpenSceneGraph_Data/cow.osg");
    osgUtil::Optimizer optimizer;
    optimizer.optimize(pNode);
    pViewer->setSceneData(pNode);
}
void Widget::initOsgWindow()
{
    _viewer = _pOsgWidget->getOsgViewer();
    _viewer->getCamera()->setClearMask(GL_DEPTH_BUFFER_BIT);
    _viewer->setCameraManipulator(new osgGA::TrackballManipulator);
    auto *option =  new osgDB::Options("noTriStripPolygons");
    Registry::instance()->setOptions(option);
    _viewer->setSceneData(osgDB::readNodeFile("G:/osgENV/OpenSceneGraph_Data/cow.osg"));
}

main.cpp文件

#include "widget.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();
    return a.exec();
}

 

标签:Qt5.15,osgQt,lib,VS2019,osg365Vs2019x64,Widget,osgENV,include,osg365
From: https://www.cnblogs.com/lishanyang/p/17022418.html

相关文章

  • C++:OutputDebugString作用(以VS2019为演示例子)
    上最简单的代码:#include<iostream>#include<Windows.h>usingnamespacestd;intmain(){OutputDebugString(L"输出调DD试信息123");cout<<"HelloWorld!\n";}......
  • VS2019发布至远程IIS部署流程
    服务器部署传统的开发将项目发布至本地桌面之后,复制至站点目录或通过FTP上传站点目录,有点小麻烦,通过开发工具VS2019本身集成的功能,可以一步到发布到远程IIS站点。条件:V......
  • Qt5.15-windows安装(解决Network error while downloading问题)
    ​​文章目录​​1项目场景:​​​​2问题描述:​​​​3原因分析:​​​​4解决方案:​​​​4.1下载fiddlereverywhere以及qt在线下载器​​​​4.2在fiddlereverywh......
  • VS2019创建win32项目
                   ......
  • vs2017 vs2019秘钥
    VS2017专业版和企业版激活密钥需要的请自取~Enterprise:NJVYC-BMHX2-G77MM-4XJMR-6Q8QFProfessional:KBJFW-NXHK6-W4WJM-CRMQB-G3CDH Visual Studio 2019 Enterprise企......
  • VS2019专业版下载
    关注微信公众号【工控羊】或者微信号【gksheep】,微信公众号后台输入数字编号【0001】即可获取下载链接。......
  • vs2019 配置 qt 库
    如标题所说,在vs编译器中调用qt库首先安装一个适合vs的qt版本不知道怎么安装的,可以参考:VisualStudio+Qt配置开发环境qt安装之后,我们只需要在vs编译器中设置......
  • VS2019使用Qt4.8.7
    取消系统变量中的Qt_INCLUDEPATH_。C:\Users\octob\AppData\Local\QtMsBuild中添加qt4.natvis.xml,qt4.natvisforvisualstudio2015forqt4IverifiedQString,Q......
  • Windows10+VS2019从源码编译 Qt5
    参考Windows10+MSVC(VS2022)从源码编译QT5.12.11-知乎(zhihu.com)qt-labs/vstools~qt-labs/vstools(github.com)BuildingQt5fromGit/zh-QtWikiQtConfi......
  • vs2019编译Qt4.8.7
    下载4.8.7源码Indexof/archive/qt/4.8/4.8.7复制mkspecs\win32-msvc2015到mkspecs\win32-msvc2019修改qmake.conf第2行:2017=>2019第4行:2017=>2019第12......