[osg-users] Adding transparency loses color

Héctor Martínez hector.martinez at sensetrix.com
Fri Oct 23 02:08:15 PDT 2015


Hello,


When I try to add transparency to a loaded model, the original color of the
model is lost. In some cases, the color stays and gets darker (and
semi-transparent), but in other it just disappears and turns grey (and
semi-transparent). I am sure I am doing something wrong, but it happens even
with the simplest code. For example:

 

osgViewer::Viewer viewer;

osg::ref_ptr<osg::Node> model = osgDB::readNodeFile("cow.osgt");

            

osg::ref_ptr<osg::StateSet> ss = model->getOrCreateStateSet();

osg::ref_ptr<osg::Material> blendMaterial = new osg::Material;

blendMaterial->setAlpha(osg::Material::FRONT_AND_BACK, 1);

ss->setAttributeAndModes( blendMaterial.get() , osg::StateAttribute::ON |
osg::StateAttribute::OVERRIDE);

osg::ref_ptr<osg::BlendFunc> bf = new
osg::BlendFunc(osg::BlendFunc::SRC_ALPHA,
osg::BlendFunc::ONE_MINUS_SRC_ALPHA );

ss->setAttributeAndModes(bf);

 

viewer.setSceneData( model.get() );

return viewer.run(); 

 

It happens even if I set the alpha value to 1, which if I understand it
correctly, should leave the model as it is (with no semi-transparency). The
attached image shows a comparison of the model without applying the material
and the model after applying the material with alpha=1. It, of course, also
happens if I set alpha to less than 1.

 

Could someone give me some hint on what I am doing wrong?

 

Thank you in advance.

 

Best regards

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20151023/1cdfa3e7/attachment-0002.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: alpha.jpg
Type: image/jpeg
Size: 91587 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20151023/1cdfa3e7/attachment-0002.jpg>


More information about the osg-users mailing list