Added new osgscribe demo which demostrates how to create a wireframe
overlay of a model.
This commit is contained in:
parent
78fc28be7c
commit
f9f9c577a8
@ -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
|
||||
|
22
src/Demos/osgscribe/Makefile
Normal file
22
src/Demos/osgscribe/Makefile
Normal file
@ -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
|
||||
|
145
src/Demos/osgscribe/osgscribe.cpp
Normal file
145
src/Demos/osgscribe/osgscribe.cpp
Normal file
@ -0,0 +1,145 @@
|
||||
#include <osg/Transform>
|
||||
#include <osg/Billboard>
|
||||
#include <osg/Geode>
|
||||
#include <osg/Group>
|
||||
#include <osg/Notify>
|
||||
#include <osg/Material>
|
||||
#include <osg/PolygonOffset>
|
||||
#include <osg/PolygonMode>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#include <osgUtil/TrackballManipulator>
|
||||
#include <osgUtil/FlightManipulator>
|
||||
#include <osgUtil/DriveManipulator>
|
||||
|
||||
#include <osgGLUT/glut>
|
||||
#include <osgGLUT/Viewer>
|
||||
|
||||
#include <osgUtil/Optimizer>
|
||||
|
||||
void write_usage(std::ostream& out,const std::string& name)
|
||||
{
|
||||
out << std::endl;
|
||||
out <<"usage:"<< std::endl;
|
||||
out <<" "<<name<<" [options] infile1 [infile2 ...]"<< std::endl;
|
||||
out << std::endl;
|
||||
out <<"options:"<< std::endl;
|
||||
out <<" -l libraryName - load plugin of name libraryName"<< std::endl;
|
||||
out <<" i.e. -l osgdb_pfb"<< std::endl;
|
||||
out <<" Useful for loading reader/writers which can load"<< std::endl;
|
||||
out <<" other file formats in addition to its extension."<< std::endl;
|
||||
out <<" -e extensionName - load reader/wrter plugin for file extension"<< std::endl;
|
||||
out <<" i.e. -e pfb"<< std::endl;
|
||||
out <<" Useful short hand for specifying full library name as"<< std::endl;
|
||||
out <<" done with -l above, as it automatically expands to"<< std::endl;
|
||||
out <<" the full library name appropriate for each platform."<< std::endl;
|
||||
out <<std::endl;
|
||||
out <<" -stereo - switch on stereo rendering, using the default of,"<< std::endl;
|
||||
out <<" ANAGLYPHIC or the value set in the OSG_STEREO_MODE "<< std::endl;
|
||||
out <<" environmental variable. See doc/stereo.html for "<< std::endl;
|
||||
out <<" further details on setting up accurate stereo "<< std::endl;
|
||||
out <<" for your system. "<< std::endl;
|
||||
out <<" -stereo ANAGLYPHIC - switch on anaglyphic(red/cyan) stereo rendering."<< std::endl;
|
||||
out <<" -stereo QUAD_BUFFER - switch on quad buffered stereo rendering."<< std::endl;
|
||||
out <<std::endl;
|
||||
out <<" -stencil - use a visual with stencil buffer enabled, this "<< std::endl;
|
||||
out <<" also allows the depth complexity statistics mode"<< std::endl;
|
||||
out <<" to be used (press 'p' three times to cycle to it)."<< std::endl;
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
|
||||
// initialize the GLUT
|
||||
glutInit( &argc, argv );
|
||||
|
||||
if (argc<2)
|
||||
{
|
||||
write_usage(osg::notify(osg::NOTICE),argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// create the commandline args.
|
||||
std::vector<std::string> commandLine;
|
||||
for(int i=1;i<argc;++i) commandLine.push_back(argv[i]);
|
||||
|
||||
|
||||
// initialize the viewer.
|
||||
osgGLUT::Viewer viewer;
|
||||
|
||||
// configure the viewer from the commandline arguments, and eat any
|
||||
// parameters that have been matched.
|
||||
viewer.readCommandLine(commandLine);
|
||||
|
||||
// configure the plugin registry from the commandline arguments, and
|
||||
// eat any parameters that have been matched.
|
||||
osgDB::readCommandLine(commandLine);
|
||||
|
||||
// load the nodes from the commandline arguments.
|
||||
osg::Node* loadedModel = osgDB::readNodeFiles(commandLine);
|
||||
if (!loadedModel)
|
||||
{
|
||||
write_usage(osg::notify(osg::NOTICE),argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// to do scribe mode we create a top most group to contain the
|
||||
// original model, and then a second group contains the same model
|
||||
// but overrides various state attributes, so that the second instance
|
||||
// is rendered as wireframe.
|
||||
|
||||
osg::Group* rootnode = new osg::Group;
|
||||
|
||||
osg::Group* decorator = new osg::Group;
|
||||
|
||||
rootnode->addChild(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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user