[编程经验][Osg]代码片段

Hello World

#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/StateSetManipulator>
#include <osgDB/ReadFile>

int main(int argc, char *argv[]) {
    ref_ptr<osgViewer::Viewer> v = new osgViewer::Viewer;

    v->setUpViewInWindow(100, 100, 800, 800);

    // add the state manipulator
    v->addEventHandler(new osgGA::StateSetManipulator(v->getCamera()->getOrCreateStateSet()));

    // add the thread model handler
    v->addEventHandler(new osgViewer::ThreadingHandler);

    // add the window size toggle handler
    v->addEventHandler(new osgViewer::WindowSizeHandler);

    // add the stats handler
    v->addEventHandler(new osgViewer::StatsHandler);

    // add the help handler
    v->addEventHandler(new osgViewer::HelpHandler());

    v->setSceneData(osgDB::readNodeFile("cow.osg"));

    v->realize();

    return v->run();
}

创建相机

  ref_ptr<Camera> c = new Camera;
  c->setName("Camera");
  c->setRenderOrder(Camera::POST_RENDER, 2);
  c->setReferenceFrame(Transform::ReferenceFrame::ABSOLUTE_RF);
  c->setViewMatrix(Matrix::identity());
  c->setProjectionMatrix(Matrix::identity());
  c->setViewport(0, 0, OIT_BUFFER_WIDTH, OIT_BUFFER_HEIGHT);
  c->setClearMask(GL_COLOR_BUFFER_BIT);
  c->setClearColor(Vec4(0, 0, 0, 0));
  c->setColorMask(true, true, true, true);
  c->setRenderTargetImplementation(Camera::FRAME_BUFFER_OBJECT);
  c->attach(Camera::COLOR_BUFFER, ft);
  c->setAllowEventFocus(false);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值