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

最新文章

  1. MongoDB 初见指南
  2. python(19)编码问题
  3. luigi学习9--执行模型
  4. HTTP 协议简介
  5. checkbox 实现单选效果(html)
  6. 从点击到呈现 — 详解一次HTTP请求
  7. shell脚本交互:expect学习笔记及实例详解
  8. Objective-C中整数与字符串的相互转换
  9. Tomcat基本配置
  10. java虚拟机——垃圾回收机制
  11. matlab sign函数用法及实例
  12. 推荐一个spring cloud 学习路线,绝对合理化
  13. RSA 加解密 秘钥对说明
  14. canvas 实现微信小游戏
  15. SSM(Spring MVC +Spring+Mybatis)整合——maven工程
  16. 最短路径Dijkstra matlab
  17. 修改cnblogs日历控件CSS
  18. NavigationViewController页面间通信及传值
  19. C - 前m大的数 (结构体)
  20. java.util.ConcurrentModificationException: null

热门文章

  1. MongoDB安装成为Windows服务
  2. 冒泡排序的思想 python 冒泡排序、递归排序
  3. 配置Anaconda的jupyter notebook默认主页
  4. 操作MySQL数据库相关代码
  5. 【转】mybatis循环map的一些技巧
  6. text-overflow的用法
  7. 存储过程 ----- navicat 创建存储过程
  8. poj 3230(初始化。。动态规划)
  9. Delphi Socket通信及多线程编程总结
  10. linux--redis的安装和配置和开启多个端口