OSG设置网格模型半透明

设置网格模型半透明:

osg::ref_ptr<osg::BlendColor> blendColor = new osg::BlendColor(osg::Vec4d(1.0,1.0,1.0,0.0));
blendColor->setConstantColor(osg::Vec4d(1.0,1.0,1.0,0.3));
osg::ref_ptr<osg::BlendFunc> blendFunc = new osg::BlendFunc;
blendFunc->setSource(osg::BlendFunc::CONSTANT_ALPHA);
blendFunc->setDestination(osg::BlendFunc::ONE_MINUS_CONSTANT_ALPHA);

osg::StateSet* st = node->getOrCreateStateSet();
st->setMode(GL_LIGHTING,osg::StateAttribute::OFF|osg::StateAttribute::PROTECTED);
st->setMode(GL_BLEND,osg::StateAttribute::ON);
st->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
st->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
st->setAttributeAndModes(blendColor,osg::StateAttribute::ON);
st->setAttributeAndModes(blendFunc,osg::StateAttribute::ON);

恢复原始状态:

osg::StateSet* st = node->getOrCreateStateSet();
st->setMode(GL_LIGHTING,osg::StateAttribute::ON|osg::StateAttribute::PROTECTED);
st->setMode(GL_BLEND,osg::StateAttribute::OFF);
st->setMode(GL_DEPTH_TEST,osg::StateAttribute::ON);
st->setRenderingHint(osg::StateSet::DEFAULT_BIN);
st->setAttributeAndModes(blendColor,osg::StateAttribute::OFF);
st->setAttributeAndModes(blendFunc,osg::StateAttribute::OFF);

猜你喜欢

转载自blog.csdn.net/qq_45523399/article/details/126592694
今日推荐