OSG设置半透明显示,需要设置显示颜色的alpha值小于1,且开启融合模式,设置渲染方式为透明方式。
osg::Geometry* polyGeom = new osg::Geometry();
//颜色为半透明颜色
osg::ref_ptr<osg::Vec4Array> shared_colors = new osg::Vec4Array;
shared_colors->push_back(osg::Vec4(1.0f,0.0f,0.0f,0.2f));//注意最末尾的0.2
polyGeom->setColorArray(shared_colors.get());
//开启融合操作
polyGeom ->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
//设置渲染模式
polyGeom ->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
//关闭光照,这样任意面,都可以看到半透明效果。
polyGeom ->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);