diff --git a/src/Demos/hangglide/base.cpp b/src/Demos/hangglide/base.cpp index 38531024e..c390e2549 100644 --- a/src/Demos/hangglide/base.cpp +++ b/src/Demos/hangglide/base.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -15,7 +16,7 @@ Node *makeBase( void ) int i, c; float theta; float ir, ori; - ir = 6.0; + ir = 0.0; ori = 20.0; Vec3 *coords = new Vec3[38]; @@ -85,6 +86,15 @@ Node *makeBase( void ) gstate->setAttr( PFSTATE_FOG, fog ); */ + // clear the depth to the far plane. + osg::Depth* depth = new osg::Depth; + depth->setFunction(osg::Depth::ALWAYS); + depth->setRange(1.0,1.0); + dstate->setAttributeAndModes(depth,StateAttribute::ON ); + + dstate->setRenderBinDetails(-1,"RenderBin"); + + gset->setStateSet( dstate ); Geode *geode = new Geode; diff --git a/src/Demos/hangglide/hangglide.cpp b/src/Demos/hangglide/hangglide.cpp index 8327ab0c1..7d95c4377 100644 --- a/src/Demos/hangglide/hangglide.cpp +++ b/src/Demos/hangglide/hangglide.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #include #include @@ -123,11 +125,19 @@ int main( int argc, char **argv ) // no database loaded so automatically create Ed Levin Park.. osg::Group* group = new osg::Group; rootnode = group; - group->addChild(makeTerrain()); - group->addChild(makeTank()); - group->addChild(makeSky()); - group->addChild(makeBase()); - group->addChild(makeTrees()); + + // the base and sky subgraphs go to set the earth sky of the + // model and clear the color and depth buffer for us, by using + // osg::Depth, and setting their bin numbers to less than 0, + // to force them to draw before the rest of the scene. + + group->addChild(makeSky()); // bin number -2 so drawn first. + group->addChild(makeBase()); // bin number -1 so draw second. + + // the rest of the scene drawn after the base and sky above. + group->addChild(makeTrees()); // will drop into a transparent, depth sorted bin (1) + group->addChild(makeTerrain()); // will drop into default bin - state sorted 0 + group->addChild(makeTank()); // will drop into default bin - state sorted 0 // add the following in the future... // makeGliders // makeClouds @@ -139,6 +149,22 @@ int main( int argc, char **argv ) osgGLUT::Viewer viewer; viewer.addViewport( rootnode ); + + osg::StateSet* stateset = rootnode->getStateSet(); + if (stateset==NULL) + { + stateset = new osg::StateSet; + rootnode->setStateSet(stateset); + } + + // set up depth to be inherited by the rest of the scene unless + // overrideen. + osg::Depth* rootDepth = new osg::Depth; + rootDepth->setFunction(osg::Depth::LESS); + rootDepth->setRange(0.0,1.0); + + stateset->setAttributeAndModes(rootDepth, osg::StateAttribute::ON ); + unsigned int pos = viewer.registerCameraManipulator(new GliderManipulator()); // Open window so camera manipulator's warp pointer request will succeed @@ -146,6 +172,12 @@ int main( int argc, char **argv ) viewer.selectCameraManipulator(pos); + osgUtil::SceneView* sv = viewer.getViewportSceneView(0); + + // switch off the render stages clear mask as we use the earth/sky + // to clear it for us, see above. + sv->getRenderStage()->setClearMask(0); + viewer.run(); return 0; diff --git a/src/Demos/hangglide/sky.cpp b/src/Demos/hangglide/sky.cpp index 7e285093e..9770b7a5f 100644 --- a/src/Demos/hangglide/sky.cpp +++ b/src/Demos/hangglide/sky.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -96,6 +97,15 @@ Node *makeSky( void ) dstate->setAttribute( new TexEnv ); dstate->setMode( GL_LIGHTING, StateAttribute::OFF ); dstate->setMode( GL_CULL_FACE, StateAttribute::ON ); + + + // clear the depth to the far plane. + osg::Depth* depth = new osg::Depth; + depth->setFunction(osg::Depth::ALWAYS); + depth->setRange(1.0,1.0); + dstate->setAttributeAndModes(depth,StateAttribute::ON ); + + dstate->setRenderBinDetails(-2,"RenderBin"); gset->setStateSet( dstate ); diff --git a/src/Demos/osgreflect/osgreflect.cpp b/src/Demos/osgreflect/osgreflect.cpp index a2d65afdd..2a0b68937 100644 --- a/src/Demos/osgreflect/osgreflect.cpp +++ b/src/Demos/osgreflect/osgreflect.cpp @@ -301,7 +301,8 @@ int main( int argc, char **argv ) osg::ColorMask* rootColorMask = new osg::ColorMask; rootColorMask->setMask(true,true,true,true); - // set up depth so all writing to depth goes to maximum depth. + // set up depth to be inherited by the rest of the scene unless + // overrideen. this is overridden in bin 3. osg::Depth* rootDepth = new osg::Depth; rootDepth->setFunction(osg::Depth::LESS); rootDepth->setRange(0.0,1.0);