提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
一、设置Texture的时候绑定Image
创建image
auto image = new osg::Image;
image->allocateImage(viewport->width(), viewport->height(), 1, GL_RGBA, GL_UNSIGNED_BYTE);
绑定texture
auto texture = new osg::TextureRectangle;
texture->setImage(image);
二、osg::Camera::DrawCallback或者osg::GraphicsOperation
基本实现是继承这两个类,重写其下面这个函数
virtual void operator ()
区别是执行时机不同,osg::Camera::DrawCallback会在绑定相机执行完成之后执行(对texture2d等也有效),osg::GraphicsOperation会在所有相机执行完之后执行,可以在其中借助osg上下文进行opengl函数处理(测试只对osg::TextureRectangle有效)。
三、通过绑定的Image获取Texture信息
osg::GraphicsOperation的时候,如下获取(context为函数参数):
image->readImageFromCurrentTexture(context->getState()->getContextID(),0);
osg::Camera::DrawCallback的时候,如下获取(renderInfo为函数参数,_texture为获取的osg::Texture2D等):
renderInfo.getState()->applyAttribute(_texture);
image->readImageFromCurrentTexture(renderInfo->getState()->getContextID(),0);
注意:readImageFromCurrentTexture这个函数需要注意第三个参数是有默认值的,如果是GL_FLOAT进行存储的,要回写的时候,第三个参数要填入GL_FLOAT,否则Image的_dataType会被更新为GL_UNSIGNED_BYTE,导致getColor函数取值出错。
四、处理Texture2D会被自动处理为2^n大小造成的问题(_texture为osg::Texture2D)
_texture->setResizeNonPowerOfTwoHint(false)
819

被折叠的 条评论
为什么被折叠?



