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"));
}