Created a switch node for which I set true and false values, and it works.
The Geodes contain one texture each. I declared buttonSwitch as a global,
outside main.
Code:
osg::ref_ptr<osg::Switch> buttonSwitch = new osg::Switch;
osg::ref_ptr<osg::Geode> geode1 = new osg::Geode;
osg::ref_ptr<osg::Geode> geode2 = new osg::Geode;
geode1->addDrawable( quad1.get() );
geode2->addDrawable( quad2.get() );
buttonSwitch->addChild(geode1.get(),false);
buttonSwitch->addChild(geode2.get(),true);
camera->addChild( buttonSwitch.get() );
But when I try to switch on a mouse click, it does not work
Code:
virtual bool handle( const osgGA::GUIEventAdapter& ea,
osgGA::GUIActionAdapter& aa )
{
osgViewer::View* view = static_cast<osgViewer::View*>(&aa);
if ( view )
{
switch ( ea.getEventType() )
{
case osgGA::GUIEventAdapter::PUSH:
std::cout<<"Push"<<std::endl;
if (buttonSwitch->getValue(0))
{buttonSwitch->setValue(0,false);buttonSwitch->setValue(1,true);}
else
{buttonSwitch->setValue(0,true);buttonSwitch->setValue(1,false);}
break;
The control reaches the setValue line. I checked with a breakpoint. But I don't
see the textures switching between visible and not visible. Is some kind of a
refresh required to show the switched texture?
Additionally, I was using this technique to implement a button on my screen,
since I found osg Widgets to be unreliable. Hope it's a good thing to implement
my own navigation controls using textures as buttons and screenspace items? I
didn't want to use MFC buttons coz my app would soon be ported to Linux.
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=48552#48552
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org