osgQt Windows编译和使用 OSG3.6.4 VS2019 Qt5.15.2 CMAKE3.20

osgQt Windows编译和使用 OSG3.6.4 VS2019 Qt5.15.2 CMAKE3.20

1、我拉了最新的osgQt的源码 osgQt的CSDN镜像  ,

OSG在之前准备好3.6.4的已编译好的版本 内部版本号160,OSG的编译到处都是,详细内容推荐 OSG详细编译教程,我写的几个小坑在上一篇 几个编译Windows OSG需要注意的问题

2、注意系统path的添加,

3、cmake使用的时候注意configure后是否都寻找到了路径,第一次CMAKE_BUILD_TYPE 写 "Debug" POSTFIX 写 "d" ,第二次改Release ,删掉"d",这样编译出的两种lib能放在一个文件夹里 

4、编译完成后 管理员权限打开VS2019 打开.sln,编译debug ,再生成install,完成后退出到上一步换Release, 再来一次

5、使用:QtCreator qmake .pro

QT       += core widgets


CONFIG += c++11


SOURCES += \
    main.cpp \
    widget.cpp

HEADERS += \
    widget.h



Osg_qt          =  $$PWD/osgQt
INCLUDEPATH     += $${Osg_qt}/include
CONFIG(debug, debug|release){
    LIBS += $${Osg_qt}/lib/osgQOpenGLd.lib
}else
{
    LIBS += $${Osg_qt}/lib/osgQOpenGL.lib
}

6、添加了osgQOpenGLWidget* 这个类,添加到Qt布局中

#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:
    explicit Widget(QWidget *parent = nullptr);

protected slots:
    void initOsgWindow();
private:
    osgQOpenGLWidget* _pOsgWidget;
    osg::ref_ptr<osgViewer::Viewer> _viewer;

signals:

};

#endif // WIDGET_H
#include "widget.h"
#include <QHBoxLayout>
#include <osgDB/ReadFile>
#include <osgDB/Options>
using namespace osgDB;
Widget::Widget(QWidget *parent) : QWidget(parent)
{
    _pOsgWidget = new osgQOpenGLWidget(this);
    connect(_pOsgWidget, SIGNAL(initialized()), this, SLOT(initOsgWindow()));
    QHBoxLayout * layout = new QHBoxLayout;
    setLayout(layout);
    layout->addWidget(_pOsgWidget);

}

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("D:/file/stl/up.stl"));
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Hsj1994

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值