From Ulrich Hertlein, "attached is a stencil buffer-based constant-width outline f/x with example. I've also modified osgfxbrowser to setup the stencil buffer accordingly."

This commit is contained in:
Robert Osfield
2009-12-08 17:41:44 +00:00
parent 17b8ee1508
commit e0154c2d28
8 changed files with 357 additions and 0 deletions

View File

@@ -41,6 +41,7 @@ IF(DYNAMIC_OPENSCENEGRAPH)
ADD_SUBDIRECTORY(osgfont)
ADD_SUBDIRECTORY(osgforest)
ADD_SUBDIRECTORY(osgfxbrowser)
ADD_SUBDIRECTORY(osgoutline)
ADD_SUBDIRECTORY(osggameoflife)
ADD_SUBDIRECTORY(osggeodemo)
ADD_SUBDIRECTORY(osggeometry)

View File

@@ -320,6 +320,12 @@ int main(int argc, char *argv[])
viewer.setThreadingModel(threading);
// setup stencil buffer for Outline f/x.
osg::DisplaySettings::instance()->setMinimumNumStencilBits(1);
unsigned int clearMask = viewer.getCamera()->getClearMask();
viewer.getCamera()->setClearMask(clearMask | GL_STENCIL_BUFFER_BIT);
viewer.getCamera()->setClearStencil(0);
// any option left unread are converted into errors to write out later.
arguments.reportRemainingOptionsAsUnrecognized();

View File

@@ -0,0 +1,6 @@
#this file is automatically generated
SET(TARGET_SRC osgoutline.cpp )
SET(TARGET_ADDED_LIBRARIES osgFX osgGA )
#### end var setup ###
SETUP_EXAMPLE(osgoutline)

View File

@@ -0,0 +1,46 @@
// -*-c++-*-
/*
* Draw an outline around a model.
*/
#include <osg/Group>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osgFX/Outline>
int main(int argc, char** argv)
{
osg::ArgumentParser arguments(&argc,argv);
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] <file>");
arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
// create outline effect
osg::ref_ptr<osgFX::Outline> outline = new osgFX::Outline;
outline->setWidth(8);
outline->setColor(osg::Vec4(1,1,0,1));
// create scene
osg::ref_ptr<osg::Group> root = new osg::Group;
root->addChild(outline);
osg::ref_ptr<osg::Node> model0 = osgDB::readNodeFile(arguments.argc() > 1 ? arguments[1] : "al.obj");
outline->addChild(model0);
// must have stencil buffer...
osg::DisplaySettings::instance()->setMinimumNumStencilBits(1);
// construct the viewer
osgViewer::Viewer viewer;
viewer.setSceneData(root);
// must clear stencil buffer...
unsigned int clearMask = viewer.getCamera()->getClearMask();
viewer.getCamera()->setClearMask(clearMask | GL_STENCIL_BUFFER_BIT);
viewer.getCamera()->setClearStencil(0);
return viewer.run();
}