0

I have 2 functions, one to enter and to exit the wireframe mode:

void enterWireFrame(const osgGA::GUIEventAdapter& ea, osgViewer::Viewer* viewer)
{
  osg::Node* scene = viewer->getSceneData();

  osg::Group* parent = scene->getParent(0);
  osg::Node* node = parent->getChild(0);

  auto scribe = new osgFX::Scribe();
  scribe->addChild(node);

  parent->replaceChild(node, scribe);
}

And to exit:

void exitWireFrame(const osgGA::GUIEventAdapter& ea, osgViewer::Viewer* viewer)
{
    osg::Node* scene = viewer->getSceneData();

    osg::Group* parent = scene->getParent(0);
    osg::Node* node = (dynamic_cast<osg::Group*>(scene))->getChild(0);

    parent->replaceChild(parent, node);
}

Basically I ran the program in this sequence:

enterWireFrame(...);
exitWireFrame(...);

The enterWireFrame() renders the wireframe okay, but I am unable to get back the original non-wireframe look, despite running exitWireFrame().

John Tan
  • 1,331
  • 1
  • 19
  • 35

1 Answers1

0

Entering and exiting wireframe mode can easily be achieved by adding a PolygonMode attribute to the stateset of your node. Check osgGA::StateSetManipulator::cyclePolygonMode for implementation details. Actually, the 'w' key, unless overridden already does this toggling for you.

sn710
  • 581
  • 5
  • 20