svope
svope

Reputation: 31

OSG - Creating overlaying, always on top rendering statusbar?

I made a scene, where I detect some collisions (intersections) and I want to show progress of that collision (like interaction with objects). For example, you are pointing at light switch and there is circle which is filled based on time spent pointing at the switch, so the light would turn on/off after some timer period.

That "filling cricle/ status bar" is saved in images 1.png, 2.png...

//that "filling circle progress" is saved in images
osg::ref_ptr<osg::Image> image1 = osgDB::readImageFile("1.png");
osg::ref_ptr<osg::Texture2D> texture1 = new osg::Texture2D;
texture1->setImage( image1.get() );

//create textured quad
osg::ref_ptr<osg::Geometry> quad1 = osg::createTexturedQuadGeometry( osg::Vec3(-0.5f, 0.0f,-0.5f),
                                                                            osg::Vec3(1.0f,0.0f,0.0f),
                                                                            osg::Vec3(0.0f,0.0f,1.0f) );

osg::StateSet* ss1 = quad1->getOrCreateStateSet();
ss1->setTextureAttributeAndModes( 0, texture1.get() );
ss1->setMode(GL_BLEND,osg::StateAttribute::ON); 
ss1->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); 

// I want that the "filling circle" will be always faced toward camera, so I use Billboards
osg::ref_ptr<osg::Billboard> timer1 = new osg::Billboard;
timer1->setMode(osg::Billboard::POINT_ROT_EYE);
timer1->addDrawable( quad1.get());

// I switch between 4 different states - 1/4 of circle, 2/4, 3/4, 4/4..
// thats why I use Switch
osg::Switch* switcher = new osg::Switch;
switcher->addChild( timer1.get(),true);

// just rootNode of scene
rootNode->addChild( switcher);

So, this works great but the problem is that sometimes the "statusbar=filling circle" is covered by some other object ( based on depth buffer I guess). What should I use to make my status bar render always on top of everything?

I tried to make a HUD camera, but that didnt work for me ( it just didnt render ) and I dont know if it's even the right way how to do it.

Thanks

Upvotes: 0

Views: 1179

Answers (1)

XenonofArcticus
XenonofArcticus

Reputation: 472

Usually you turn off depth testing and depth writes and put the HUD-like item into a renderbin that renders after all the other stuff. I think there are examples of how to do this, probably in the osg HUD examples.

Upvotes: 1

Related Questions