mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-29 22:15:32 +00:00
Seems to fix wireframe crashes
This commit is contained in:
parent
2eedb3acec
commit
31a0bbcb23
1 changed files with 25 additions and 10 deletions
|
@ -17,9 +17,8 @@
|
|||
class WireframeKeyHandler : public osgGA::GUIEventHandler
|
||||
{
|
||||
public:
|
||||
WireframeKeyHandler(osg::Node* node)
|
||||
WireframeKeyHandler()
|
||||
: mWireframe(false)
|
||||
, mNode(node)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -32,12 +31,7 @@ public:
|
|||
if (adapter.getKey() == osgGA::GUIEventAdapter::KEY_W)
|
||||
{
|
||||
mWireframe = !mWireframe;
|
||||
osg::PolygonMode* mode = new osg::PolygonMode;
|
||||
mode->setMode(osg::PolygonMode::FRONT_AND_BACK,
|
||||
mWireframe ? osg::PolygonMode::LINE : osg::PolygonMode::FILL);
|
||||
mNode->getOrCreateStateSet()->setAttributeAndModes(mode, osg::StateAttribute::ON);
|
||||
mNode->getOrCreateStateSet()->setMode(GL_CULL_FACE, mWireframe ? osg::StateAttribute::OFF
|
||||
: osg::StateAttribute::ON);
|
||||
// applying state from an event handler doesn't appear to be safe, so do it in the frame update
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
|
@ -46,9 +40,13 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
bool getWireframe() const
|
||||
{
|
||||
return mWireframe;
|
||||
}
|
||||
|
||||
private:
|
||||
bool mWireframe;
|
||||
osg::Node* mNode;
|
||||
};
|
||||
|
||||
int main(int argc, char** argv)
|
||||
|
@ -93,11 +91,28 @@ int main(int argc, char** argv)
|
|||
viewer.setUpViewInWindow(0, 0, 800, 600);
|
||||
viewer.realize();
|
||||
viewer.setCameraManipulator(new osgGA::TrackballManipulator());
|
||||
viewer.addEventHandler(new WireframeKeyHandler(root));
|
||||
|
||||
WireframeKeyHandler* keyHandler = new WireframeKeyHandler;
|
||||
|
||||
viewer.addEventHandler(keyHandler);
|
||||
viewer.addEventHandler(new osgViewer::StatsHandler);
|
||||
|
||||
bool wireframe = false;
|
||||
|
||||
while (!viewer.done())
|
||||
{
|
||||
|
||||
if (wireframe != keyHandler->getWireframe())
|
||||
{
|
||||
wireframe = keyHandler->getWireframe();
|
||||
osg::PolygonMode* mode = new osg::PolygonMode;
|
||||
mode->setMode(osg::PolygonMode::FRONT_AND_BACK,
|
||||
wireframe ? osg::PolygonMode::LINE : osg::PolygonMode::FILL);
|
||||
root->getOrCreateStateSet()->setAttributeAndModes(mode, osg::StateAttribute::ON);
|
||||
root->getOrCreateStateSet()->setMode(GL_CULL_FACE, wireframe ? osg::StateAttribute::OFF
|
||||
: osg::StateAttribute::ON);
|
||||
}
|
||||
|
||||
viewer.frame();
|
||||
|
||||
for (unsigned int i=0; i<controllers.size(); ++i)
|
||||
|
|
Loading…
Reference in a new issue