From f9f9c577a84ff74ee20229fbeaeb035a2811224f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 26 Jan 2002 19:48:37 +0000 Subject: [PATCH] Added new osgscribe demo which demostrates how to create a wireframe overlay of a model. --- src/Demos/Makefile | 2 +- src/Demos/osgscribe/Makefile | 22 +++++ src/Demos/osgscribe/osgscribe.cpp | 145 ++++++++++++++++++++++++++++++ 3 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 src/Demos/osgscribe/Makefile create mode 100644 src/Demos/osgscribe/osgscribe.cpp diff --git a/src/Demos/Makefile b/src/Demos/Makefile index 4197d754a..857263d9b 100644 --- a/src/Demos/Makefile +++ b/src/Demos/Makefile @@ -1,7 +1,7 @@ #!smake SHELL=/bin/sh -DIRS = sgv osgconv osgcube osgreflect osgtexture osgimpostor osgviews hangglide +DIRS = sgv osgconv osgcube osgscribe osgreflect osgtexture osgimpostor osgviews hangglide # comment out if you don't have the freetype and GLU1.3 library installed. DIRS += osgtext diff --git a/src/Demos/osgscribe/Makefile b/src/Demos/osgscribe/Makefile new file mode 100644 index 000000000..a6f543418 --- /dev/null +++ b/src/Demos/osgscribe/Makefile @@ -0,0 +1,22 @@ +#!smake +include $(OSGHOME)/Make/makedefs + +C++FILES = \ + osgscribe.cpp + +TARGET = $(OSGHOME)/bin/osgscribe + +TARGET_BIN_FILES = osgscribe + +#note, standard library list. +LIBS = -losgGLUT -losgUtil -losgDB -losg $(GLUTLIB) $(GL_LIBS) $(X_LIBS) + +#under Darwin we have to use the framework stuff to get GLUT OpenGL etc. +MACOSXLIBS = -losgGLUT -losgUtil -losgDB -losg -lm -ldl -lstdc++ -lobjc + + +C++FLAGS += -I$(OSGHOME)/include +LDFLAGS += -L$(OSGHOME)/lib + +include $(OSGHOME)/Make/makerules + diff --git a/src/Demos/osgscribe/osgscribe.cpp b/src/Demos/osgscribe/osgscribe.cpp new file mode 100644 index 000000000..034444905 --- /dev/null +++ b/src/Demos/osgscribe/osgscribe.cpp @@ -0,0 +1,145 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include + +#include + +void write_usage(std::ostream& out,const std::string& name) +{ + out << std::endl; + out <<"usage:"<< std::endl; + out <<" "< commandLine; + for(int i=1;iaddChild(loadedModel); + + + rootnode->addChild(decorator); + + decorator->addChild(loadedModel); + + // set up the state so that the underlying color is not seen through + // and that the drawing mode is changed to wireframe, and a polygon offset + // is added to ensure that we see the wireframe itself, and turn off + // so texturing too. + osg::StateSet* stateset = new osg::StateSet; + osg::Material* material = new osg::Material; + osg::PolygonOffset* polyoffset = new osg::PolygonOffset; + polyoffset->setFactor(-1.0f); + polyoffset->setUnits(-1.0f); + osg::PolygonMode* polymode = new osg::PolygonMode; + polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE); + stateset->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE_ON); + stateset->setAttributeAndModes(polyoffset,osg::StateAttribute::OVERRIDE_ON); + stateset->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE_ON); + stateset->setMode(GL_TEXTURE_2D,osg::StateAttribute::OVERRIDE_OFF); + decorator->setStateSet(stateset); + + + // run optimization over the scene graph + osgUtil::Optimizer optimzer; +// turn off temporarily since the above single child decorator group gets +// removed as the optimizer assumes its redundent. Will fix next. Robert. +// optimzer.optimize(rootnode); + + // add a viewport to the viewer and attach the scene graph. + viewer.addViewport( rootnode ); + + // register trackball, flight and drive. + viewer.registerCameraManipulator(new osgUtil::TrackballManipulator); + viewer.registerCameraManipulator(new osgUtil::FlightManipulator); + viewer.registerCameraManipulator(new osgUtil::DriveManipulator); + + // open the viewer window. + viewer.open(); + + // fire up the event loop. + viewer.run(); + + return 0; +}