|
本帖最后由 sunnk 于 2012-9-19 18:53 编辑
我在做对一个地形进行模板测试,隐藏指定的部分区域(在该区域后面绘制了一个盒子),隐藏该区域后显示盒子!由于对不懂模板测试,只能编码试,都修改了一天了!但是一直没能实现! 代码如下:
//创建了一个底面和四个边框面
osg::Geode* side = createSide();
osg::Geode* underside = createUnderside();
osg::Geode* upGroundSide = createUpGroudSide();
osg::Geode* upside = createUpside();
//加入Group节点
m_group_3d->addChild(side);
m_group_3d->addChild(underside);
osg::Stencil* stencil = new osg::Stencil;
stencil->setWriteMask(0);
stencil->setFunction(osg::Stencil::ALWAYS,1,1);
stencil->setOperation(osg::Stencil::KEEP,osg::Stencil::KEEP,osg::Stencil:ECR);
//得到地形节点
osg::Group* s3d = libo::getGlobalViewer().getSceneMgr()->getScene3d();
osg::Group* ground = new osg::Group;
int num = s3d->getNumChildren();
for (int i =0; i <num; ++i)
{
osg::Node* node = s3d->getChild(i);
if (node && node->getName() == "地形")
{
ground = node->asGroup();
}
}
ground->getOrCreateStateSet()->setMode(GL_DEPTH_TEST,osg::StateAttribute::ON);
ground->getOrCreateStateSet()->setAttributeAndModes(stencil,osg::StateAttribute::ON);
stencil->setFunction(osg::Stencil:ESS,1,1);
stencil->setOperation(osg::Stencil::KEEP,osg::Stencil::KEEP,osg::Stencil::REPLACE);
m_group_3d->getOrCreateStateSet()->setAttributeAndModes(stencil,osg::StateAttribute::ON);
求教啊!!!!!! |
|