Hi Andrew,

If you leave the z buffer test enabled then the z buffer will discard
fragments according to the depth test settings.   For you case you can
just disable the depth test and the second drawable to be drawn will
be rendered on top of the first.   To disable depth test simple do:

    stateset->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);

On a stateset associated with each geometry, or on node that decorates
all the objects that you want in your hud.  The osgsequence example
has a hud layer that it disables the depth test for like this.

Once you have disabled the depth test then the ordering in which the
drawables leaves will get drawn in will vary depending upon state
sorting and any bin sorting that is used (the transparent bin depth
sorts from back to front).  With the latest developer versions of the
OSG 2.9.x and svn/trunk there is support for assigning to a render bin
that sorts based on TRAVERSAL_ORDER.  You can request this bin via:

  stateset->setRenderBinDetails(11, "TraversalOrderBin");

And again decorate your HUD subgraph with this.

Robert.


On Thu, Feb 24, 2011 at 6:51 AM, Andrew Clayphan <[email protected]> wrote:
> Hi,
>
> I'm trying to understand the rendering order stuff of OSG.
>
> I'm building a small HUD example, given the code below, (picture attached of 
> what the code produces).
>
> The scene graph:
>
> viewer (with ortho camera set up)
> -> group
> -> -> quad 1 (at location 50,0) (size 456 by 456)
> -> -> quad 2 (at location 0,0) (size 256 by 800)
>
> I can't seem to figure out why the second quad keeps getting placed behind 
> the first quad. I assumed it would draw in front of it, given a standard 
> traversal.
>
> I looked at transparent/opaque bins but that didn't change anything. I also 
> don't want to mess with the z-values to achieve the ordering effect.
>
> Any ideas?
>
>
>>
>> /* based on osghud */
>>
>> #include <osgUtil/Optimizer>
>> #include <osgDB/ReadFile>
>>
>> #include <osgViewer/Viewer>
>> #include <osgViewer/CompositeViewer>
>>
>> #include <osgGA/TrackballManipulator>
>>
>> #include <osg/Material>
>> #include <osg/Geode>
>> #include <osg/BlendFunc>
>> #include <osg/Depth>
>> #include <osg/PolygonOffset>
>> #include <osg/MatrixTransform>
>> #include <osg/Camera>
>> #include <osg/RenderInfo>
>>
>> #include <osgDB/WriteFile>
>>
>> #include <osgText/Text>
>>
>> // x and y from the bottom left
>> osg::Geometry* createQuad(float x, float y, float width, float height) {
>>     osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
>>     osg::ref_ptr<osg::Image> image = osgDB::readImageFile( 
>> "Images/osg256.png" );
>>     texture->setImage( image.get() );
>>     osg::ref_ptr<osg::Geometry> quad= osg::createTexturedQuadGeometry( 
>> osg::Vec3(x, y,0.0f),//center
>>                                                                        
>> osg::Vec3(width,0.0f,0.0f),//width
>>                                                                        
>> osg::Vec3(0.0f,height,0.0) );//height
>>     osg::StateSet* ss = quad->getOrCreateStateSet();
>>     ss->setTextureAttributeAndModes( 0, texture.get() );
>>     ss->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
>>     return quad.release();
>> }
>>
>> int main( int argc, char **argv )
>> {
>>
>>     osg::ref_ptr<osg::GraphicsContext::Traits> traits = new 
>> osg::GraphicsContext::Traits;
>>     traits->x = 0;
>>     traits->y = 0;
>>     traits->width = 800;
>>     traits->height = 600;
>>     traits->windowDecoration = true;
>>     traits->doubleBuffer = true;
>>     traits->samples = 4;
>>
>>     osg::ref_ptr<osg::GraphicsContext> gc = 
>> osg::GraphicsContext::createGraphicsContext( traits.get() );
>>
>>     // construct the viewer and fix the camera to be like a hud
>>     osgViewer::Viewer viewer;
>>
>>     viewer.getCamera()->setGraphicsContext(gc);
>>
>>     
>> viewer.getCamera()->setProjectionMatrix(osg::Matrix::ortho2D(0,1280,0,1024));
>>     viewer.getCamera()->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
>>     viewer.getCamera()->setViewMatrix(osg::Matrix::identity());
>>
>>     viewer.getCamera()->setViewport(new osg::Viewport(0, 0, traits->width, 
>> traits->height) );
>>     viewer.getCamera()->setClearMask( GL_DEPTH_BUFFER_BIT | 
>> GL_COLOR_BUFFER_BIT );
>>     viewer.getCamera()->setClearColor( osg::Vec4f(1.0f, 0.2f, 0.4f, 1.0f) );
>>
>>
>>     viewer.getCamera()->setAllowEventFocus(false); // don't want the 
>> manipulator resetting the above
>>
>>     // lets put objects in the scene
>>     osg::ref_ptr<osg::Group> group = new osg::Group();
>>
>>     osg::Geode* geo = new osg::Geode();
>>
>>     // quad 1
>>     osg::ref_ptr<osg::Geometry> quad = createQuad(50,0,    456.0, 456.0);
>>     geo->addDrawable(quad);
>>
>>     // quad 2
>>     osg::ref_ptr<osg::Geometry> quad2 = createQuad(0,0,    256.0, 800.0);
>>     geo->addDrawable(quad2);
>>
>>     group->addChild(geo);
>>
>>     // set the scene to render
>>     viewer.setSceneData(group.get());
>>
>>     return viewer.run();
>>
>> }
>>
>
>
> Thank you!
>
> Cheers,
> Andrew
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=37072#37072
>
>
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to