博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
osgMulitiplerendertargets sample 中fbo使用【HTC VIVE开发中应用】
阅读量:6693 次
发布时间:2019-06-25

本文共 1949 字,大约阅读时间需要 6 分钟。

osgmultiplerendertargets.cpp  

  ......................................

  // now create the camera to do the multiple render to texture

    {
        osg::Camera* camera = new osg::Camera;
        // set up the background color and clear mask.
        camera->setClearColor(osg::Vec4(0.1f,0.1f,0.3f,1.0f));
        camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        // the camera is going to look at our input quad
        camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1,0,1));
        camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
        camera->setViewMatrix(osg::Matrix::identity());
        // set viewport
        camera->setViewport(0, 0, tex_width, tex_height);
        // set the camera to render before the main camera.
        camera->setRenderOrder(osg::Camera::PRE_RENDER);
        // tell the camera to use OpenGL frame buffer objects
        camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
        // attach the textures to use
        for (int i=0; i<NUM_TEXTURES; i++) {
            if (useMultiSample)// 使用多重渲染方式消除锯齿现象
                camera->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER0+i), textureRect[i], 0, 0, false, 4, 4);
            else
                camera->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER0+i), textureRect[i]);
        }
        // we can also read back any of the targets as an image, modify this image and push it back

    // 绑定一张image获取fbo渲染结果

        if (useImage) {
            // which texture to get the image from
            const int tex_to_get = 0;
            osg::Image* image = new osg::Image;
            if (useHDR) {
                image->allocateImage(tex_width, tex_height, 1, GL_RGBA, GL_FLOAT);
            } else {
                image->allocateImage(tex_width, tex_height, 1, GL_RGBA, GL_UNSIGNED_BYTE);
            }
            // attach the image so its copied on each frame.
            camera->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER0 + tex_to_get), image);
            camera->setPostDrawCallback(new MyCameraPostDrawCallback(image));
            // push back the image to the texture
            textureRect[tex_to_get]->setImage(0, image);
        }
        // add the subgraph to render
        camera->addChild(cam_subgraph);
        parent->addChild(camera);
    }

转载地址:http://kmcoo.baihongyu.com/

你可能感兴趣的文章
Microsoft Lync Server 2013: 配置SQL服务器数据分发
查看>>
Zabbix 日志监控
查看>>
数据挖掘里的“降维”----从五阶魔方的玩法思考
查看>>
shell脚本实例之Charpter8-9
查看>>
Error polling connection 'qemu:///system': internal error Cannot find suitable emulator for
查看>>
iptables实战
查看>>
valgrind调试CPU缓存命中率和内存泄漏
查看>>
水星三维引擎发布2.0版本 ~友情帮介绍下~
查看>>
内外网访问NAT设置
查看>>
公开课视频-《第03章 部署-IT基础架构》-大企业云桌面部署实战-在线培训-视频(奉献)...
查看>>
数字方舟,末日起航-记2012云计算架构师峰会
查看>>
CocoStudio 1.4.0.1数据编辑器使用
查看>>
6425C-Lab3 管理用户与服务帐户(2)
查看>>
Linux系统工程师的必备素质
查看>>
第一个Symfony2的长期支持版释出(Symfony 2.3.0)
查看>>
与一位同学的聊天记录
查看>>
Postfix邮件系统安装配置视频
查看>>
  如何通过今日头条引精准流量,学完即用
查看>>
如何快速的提高自己:一切取决于你自己
查看>>
Linux 3.2中回写机制的变革
查看>>