From 48d148601b8828ae859f755cc386a1448250a8ee Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 20 May 2004 22:20:39 +0000 Subject: [PATCH] Added HUD scalar bar. --- examples/osgscalarbar/osgscalarbar.cpp | 32 ++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/examples/osgscalarbar/osgscalarbar.cpp b/examples/osgscalarbar/osgscalarbar.cpp index 584e369c7..4ee30ce3c 100644 --- a/examples/osgscalarbar/osgscalarbar.cpp +++ b/examples/osgscalarbar/osgscalarbar.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -70,6 +71,31 @@ osg::Node* createScalarBar() } +osg::Node * createScalarBar_HUD() +{ + osgSim::ScalarBar * geode = new osgSim::ScalarBar; + osgSim::ScalarBar::TextProperties tp; + tp._fontFile = "fonts/times.ttf"; + geode->setTextProperties(tp); + osg::StateSet * stateset = geode->getOrCreateStateSet(); + stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF); + + stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); + stateset->setRenderBinDetails(11, "RenderBin"); + + osg::MatrixTransform * modelview = new osg::MatrixTransform; + modelview->setReferenceFrame(osg::Transform::RELATIVE_TO_ABSOLUTE); + osg::Matrixd matrix(osg::Matrixd::scale(1000,1000,1000) * osg::Matrixd::translate(120,10,0)); // I've played with these values a lot and it seems to work, but I have no idea why + modelview->setMatrix(matrix); + modelview->addChild(geode); + + osg::Projection * projection = new osg::Projection; + projection->setMatrix(osg::Matrix::ortho2D(0,1280,0,1024)); // or whatever the OSG window res is + projection->addChild(modelview); + + return projection; //make sure you delete the return sb line +} + int main( int argc, char **argv ) { // use an ArgumentParser object to manage the program arguments. @@ -107,10 +133,12 @@ int main( int argc, char **argv ) return 1; } - osg::Node* node = createScalarBar(); + osg::Group* group = new osg::Group; + group->addChild(createScalarBar()); + group->addChild(createScalarBar_HUD()); // add model to viewer. - viewer.setSceneData( node ); + viewer.setSceneData( group ); // create the windows and run the threads. viewer.realize();