第三篇 Qt 创建 osg 工程

1. 在安装后的osg 目录下拷贝  bin 和  include 目录到工程目录下;    其实也可以不用这么费劲, 只是方便对整个工程的管理, 不至于在工程中到处引用库文件;
 

2. 创建一个空白的qt项目 选择 MinGW 编译

工程结构如下

工程文件如下: 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运行:

运行结果:

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值