1. 在安装后的osg 目录下拷贝
bin 和
include 目录到工程目录下; 其实也可以不用这么费劲, 只是方便对整个工程的管理, 不至于在工程中到处引用库文件;
![](https://img-blog.csdnimg.cn/d5e572409c724896bae4daf6a37f44d9.png)
![](https://img-blog.csdnimg.cn/2c6d648ad8014b61a34ba5006b5a5e2c.png)
2. 创建一个空白的qt项目 选择 MinGW 编译
![](https://img-blog.csdnimg.cn/3e260c1adaaf47d4b41dfd1fadbb20de.png)
工程结构如下
![](https://img-blog.csdnimg.cn/134f1236f6db4f18970fc1bf8672c75d.png)
工程文件如下: osg-ex1.pro文件
CONFIG += c++11 console
CONFIG -= app_bundle
SOURCES += \
main.cpp
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
# 添加库文件
LIBS += -LF:/osg3.6.0/OsgLearnExample/osg3.6.0/bin/ -lOpenThreads
LIBS += -LF:/osg3.6.0/OsgLearnExample/osg3.6.0/bin/ -losg
LIBS += -LF:/osg3.6.0/OsgLearnExample/osg3.6.0/bin/ -losgAnimation
LIBS += -LF:/osg3.6.0/OsgLearnExample/osg3.6.0/bin/ -losgDB
LIBS += -LF:/osg3.6.0/OsgLearnExample/osg3.6.0/bin/ -losgFX
LIBS += -LF:/osg3.6.0/OsgLearnExample/osg3.6.0/bin/ -losgGA
LIBS += -LF:/osg3.6.0/OsgLearnExample/osg3.6.0/bin/ -losgManipulator
LIBS += -LF:/osg3.6.0/OsgLearnExample/osg3.6.0/bin/ -losgParticle
LIBS += -LF:/osg3.6.0/OsgLearnExample/osg3.6.0/bin/ -losgPresentation
LIBS += -LF:/osg3.6.0/OsgLearnExample/osg3.6.0/bin/ -losgShadow
LIBS += -LF:/osg3.6.0/OsgLearnExample/osg3.6.0/bin/ -losgSim
LIBS += -LF:/osg3.6.0/OsgLearnExample/osg3.6.0/bin/ -losgTerrain
LIBS += -LF:/osg3.6.0/OsgLearnExample/osg3.6.0/bin/ -losgText
LIBS += -LF:/osg3.6.0/OsgLearnExample/osg3.6.0/bin/ -losgUI
LIBS += -LF:/osg3.6.0/OsgLearnExample/osg3.6.0/bin/ -losgUtil
LIBS += -LF:/osg3.6.0/OsgLearnExample/osg3.6.0/bin/ -losgViewer
LIBS += -LF:/osg3.6.0/OsgLearnExample/osg3.6.0/bin/ -losgVolume
LIBS += -LF:/osg3.6.0/OsgLearnExample/osg3.6.0/bin/ -losgWidget
# 引入头文件
INCLUDEPATH += F:/osg3.6.0/OsgLearnExample/osg3.6.0/include
main.cpp文件
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osg/Node>
#include <osgGA/AnimationPathManipulator>
int main(void)
{
osgViewer::Viewer viewer;
viewer.setSceneData(osgDB::readNodeFile("F:\\osg3.6.0\\OpenSceneGraph-Data\\cow.osg"));
viewer.realize();// 需要realize,否则窗口为null
// 修改显示窗体大小
osgViewer::GraphicsWindow *pWnd = dynamic_cast<osgViewer::GraphicsWindow*>(viewer.getCamera()->getGraphicsContext());
if (pWnd)
{
pWnd->setWindowRectangle(400, 400, 400,400);
pWnd->setWindowDecoration(true);
}
return viewer.run();
}
选择Release运行:
![](https://img-blog.csdnimg.cn/119331fe48694c65830ffdedf31d0648.png)
运行结果: