看了视频教程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

最低0.47元/天 解锁文章
969





