|
我现在要把一个不断更新的几何体这样的一个子场景用camera attach到一个纹理,然后将纹理贴到一个_quad上显示出来。这段程序在下面,但是不管我是直接attach纹理上还是image上全都是空的,不知道问题出在哪里,请求高人帮忙看看!!
this->_quad=new osg::Geode;
this->_quad->addDrawable(osg::createTexturedQuadGeometry(osg::Vec3(0.0,-100.0,0.0),osg::Vec3(100.0,0.0,0.0),osg::Vec3(0.0,0.0,100.0)));
map->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
const osg::BoundingSphere& bs = map->getBound();
float znear = 1.0f*bs.radius();
float zfar = 3.0f*bs.radius();
// 2:1 aspect ratio as per flag geometry below.
float proj_top = 0.25f*znear;
float proj_right = 0.5f*znear;
this->_mapCamera=new osg::Camera;
this->_mapCamera->setClearColor(osg::Vec4(0.1f,0.1f,0.3f,1.0f));
this->_mapCamera->setClearMask(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
this->_mapCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
this->_mapCamera->setViewport(0,0,_width,_height);
this->_mapCamera->setRenderOrder(osg::Camera:RE_RENDER);
this->_mapCamera->setAllowEventFocus(false);
this->_mapCamera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
this->_mapCamera->setProjectionMatrixAsFrustum(-proj_right,proj_right,-proj_top,proj_top,znear,zfar);
this->_mapCamera->setViewMatrixAsLookAt(bs.center()-osg::Vec3(0.0f,2.0f,0.0f)*bs.radius(),bs.center(),osg::Vec3(0.0f,0.0f,1.0f));
_image=new osg::Image;
_image->allocateImage(_width,_height,1,GL_RGBA, GL_UNSIGNED_BYTE);
_image->setInternalTextureFormat(GL_RGBA);
this->_binTex=new osg::TextureRectangle();
//this->_binTex->setSourceFormat(GL_RGBA);
//this->_binTex->setSourceType(GL_UNSIGNED_BYTE);
this->_binTex->setInternalFormat(GL_RGBA);
this->_binTex->setFilter(osg::Texture::MIN_FILTER, osg::Texture:INEAR);
this->_binTex->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
this->_binTex->setTextureSize(_width,_height);
this->_quad->getOrCreateStateSet()->setTextureAttributeAndModes(0,this->_binTex);
this->_quad->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
this->_mapCamera->attach(osg::Camera::COLOR_BUFFER,_image);
//更新几何体
osg:rawable* mapGeom = map->getDrawable(0);
osg::Geometry* mapgm = (osg::Geometry*)mapGeom;
mapgm->setUpdateCallback(new GeometryCallback());
//this->_mapCamera->setPostDrawCallback(new MyCameraPostDrawCallback(_image,this->_binTex,percent));
this->_mapCamera->addChild(map);
this->switchMap->addChild(this->_quad);
this->switchMap->addChild(this->_mapCamera);
|
|