|
我现在有一个模型节点,想对它进行正向和背向渲染,并且渲染到纹理,具体代码设置如下:
int tex_width = 128;
int tex_height = 128;
osg::Texture2D* texture2D = new osg::Texture2D;
texture2D->setTextureSize(tex_width, tex_height);
texture2D->setInternalFormat(GL_RGBA);
texture2D->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D:INEAR);
texture2D->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
osg::StateSet* stateset = node->getOrCreateStateSet();
stateset->setMode(osg::StateAttribute::CULLFACE,osg::StateAttribute::OFF);//相应的正向是ON
//camera
osg::Camera *camera = new osg::Camera();
const osg::BoundingSphere& bs = node->getBound();
if (!bs.valid())
{
std::cout<<"the box is not valid!"<<std::endl;
}
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;
znear *= 0.9f;
zfar *= 1.1f;
// set up projection.
camera->setViewport(0,0,tex_width,tex_height);
camera->setProjectionMatrixAsFrustum(-proj_right,proj_right,-proj_top,proj_top,znear,zfar);
// set view
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera->setViewMatrixAsLookAt(bs.center()-osg::Vec3(0.0f,2.0f,0.0f)*bs.radius(),bs.center(),osg::Vec3(0.0f,0.0f,1.0f));
camera->setRenderOrder(osg::Camera:RE_RENDER);
camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
camera->attach(osg::Camera::COLOR_BUFFER,texture2D,0,0,false,0,0);
return texture2D;
运行之后就给出现中断了,不知道什么缘故? |
|