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:
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
6
examples/osgoutline/CMakeLists.txt
Normal file
6
examples/osgoutline/CMakeLists.txt
Normal 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)
|
||||
46
examples/osgoutline/osgoutline.cpp
Normal file
46
examples/osgoutline/osgoutline.cpp
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user