osg写 fbo

看了视频教程https://www.bilibili.com/video/av74285647/

感谢up主,

我试图简易地描述下,如果渲染到场景中,最简单的主摄像机

int main()
{
    osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
    osg::ref_ptr<osg::Group> grp = new osg::Group;
    std::string strFileName = "f:/test/pot.FBX";
    osg::ref_ptr<osg::Node> node = osgDB::readNodeFile(strFileName);
    grp->addChild(node);

viewer->setSceneData(grp);

    viewer->run();
}
 

 

现在不想直接绘制到场景了,绘制到面片上;或者进行后处理后再次投影到全屏中,比如hdr

 

这就用到了FBO,

这里不考虑放缩,直接用屏幕大小的面片,以后即使贴到屏幕上,也是一样的。

1,先考虑面片,


osg::Texture2D *createFloatTextureRectangle(int width, int height)
{
    osg::ref_ptr<osg::Texture2D> tex2D = new osg::Texture2D;
    tex2D->setTextureSize(width, height);
    tex2D->setInternalFormat(GL_RGBA16F_ARB);
    tex2D->setSourceFormat(GL_RGBA);
    tex2D->setSourceType(GL_FLOAT);
    return tex2D.release();
}

先获取系统分辨率,确定帧缓冲区大小
    unsigned int screenWidth, screenHeight;
    {
        osg::GraphicsContext::WindowingSystemInterface *wsInterface = osg::GraphicsContext::getWindowingSystemInterface();
        if (!wsInterface)
        {
            return -1;
        }
        wsInterface->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), screenWidth, screenHeight);

    }
    int texWidth = screenWidth;
    int texHeight = screenHeight;
    // 然后设置离屏表面的纹理,FBO涉及到3种缓冲区:深度模板,颜色和法线

这里只考虑关联颜色缓冲区的纹理
    osg::Texture2D *textureSample = createFloatTextureRectangle(texWidth, texHeight);

设置完后呢,需要关联颜色缓冲区,把颜色缓冲区的内容放在这个纹理上。这用到了采样摄像机,这里仍然采用铺满该纹理。其实,主摄像机和采样摄像机都是一样的。

// 采样像机1设置:
    {

        osg::Camera *cameraSample = new osg::Camera;// 各种采样
        grp->addChild(cameraSample);// 加入场景
        cameraSample->a

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值