[osg-users] Fade effect using the osg::BlendFunc()

0 views
Skip to first unread message

Johan Johnsson

unread,
Feb 7, 2008, 6:56:53 AM2/7/08
to osg-...@lists.openscenegraph.org
Hey all!

I need a simple fade effect, is it possible to use osg::BlendFunc for this?

osg::ref_ptr<osg::BlendFunc> wakeBlend = new osg::BlendFunc();
wakeBlend->setFunction(osg::BlendFunc::DST_COLOR, osg::BlendFunc::ZERO);

I whould like to increase the alpha value each frame, is there any way to
define the alpha or transparacy using this osg::BlendFunc?, its actually
only a model i load, which i want to fade (its a common bitmap) in and out
over 2 seconds.

--
Mr. Johan Johnsson
AutoSim AS, Strandveien 106, 9006 Tromsø
Visit us at http://www.autosim.no
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Serge Lages

unread,
Feb 7, 2008, 7:09:16 AM2/7/08
to OpenSceneGraph Users
Hi,

Yes you can do it with a osg::BlendFunc, just like that :

osg::BlendFunc    *blendFunc = new osg::BlendFunc();
osg::BlendColor    *blendColor= new osg::BlendColor(osg::Vec4(1, 1, 1, 0.0));

blendFunc->setSource(osg::BlendFunc::CONSTANT_ALPHA);
blendFunc->setDestination(osg::BlendFunc::ONE_MINUS_CONSTANT_ALPHA);
node->getOrCreateStateSet()->setAttributeAndModes(blendFunc, osg::StateAttribute::ON);
node->getOrCreateStateSet()->setAttributeAndModes(blendColor, osg::StateAttribute::ON);

Then just update the blendColor's constant color (with blendColor->setConstantColor()) by changing its alpha value.

I've done it by making a node callback which updates this value using a simple timer.
--
Serge Lages
http://www.tharsis-software.com
Reply all
Reply to author
Forward
0 new messages