|
我画了个球,想把它设为透明,代码如下:
- osg::Geode* geode = new osg::Geode();
- osg::Sphere* sphere = new osg::Sphere(osg::Vec3(0.0f,0.0f,0.0f),1);
- geode->addDrawable(new osg::ShapeDrawable(sphere));
- osg::StateSet* state = geode->getOrCreateStateSet();
- osg::BlendFunc* bf = new osg::BlendFunc();
- bf->setSourceAlpha(osg::BlendFunc::CONSTANT_ALPHA);
- bf->setDestinationAlpha(osg::BlendFunc::ONE_MINUS_CONSTANT_ALPHA);
- state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
- state->setAttributeAndModes(bf, osg::StateAttribute::ON );
- osg::Depth* depth = new osg::Depth;
- state->setAttributeAndModes(depth, osg::StateAttribute::OFF );
- osg::Group* root = new osg::Group();
- root->addChild( geode );
- osgViewer::Viewer* viewer = new osgViewer::Viewer();
- root->setStateSet(state);
- viewer->setSceneData(root);
复制代码
但是运行效果是这样的
|
|