zoukankan      html  css  js  c++  java
  • osgMulitiplerendertargets sample 中fbo使用【HTC VIVE开发中应用】

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

  • 相关阅读:
    别再为了this发愁了------JS中的this机制
    offsetLeft,Left,clientLeft的区别
    下拉菜单的实现classList.add() classList.remove() class属性的添加和删除
    for循环
    html的基本数据类型(数字,字符串, 列表, 字典)
    定时器setInterval, innerText获取文本, charAt()获取单个字符串, substring(1, content.length)获取范围内的字符串, 实现字符串的滚动效果
    定时器 setInterval(‘function()’, 2000)
    parseInt 和 parseFloat 实现字符串转换为数字
    javarscript在HTML中的调用方式 (直接调用 和文件调用)
    input文本框 放上图片img 通过padding relative和absolute 的实现
  • 原文地址:https://www.cnblogs.com/mazhenyu/p/6594439.html
Copyright © 2011-2022 走看看