here is the code
Nick

http://www.linkedin.com/in/tnick
Sent from Ünalan, İstanbul, Turkey

On Tue, Dec 29, 2009 at 7:58 PM, Trajce Nikolov <[email protected]>wrote:

> uh .. that was from my testing. Replace NESTED_RENDER with POST_RENDER
>
> Nick
>
> http://www.linkedin.com/in/tnick
> Sent from Ünalan, İstanbul, Turkey
>
> On Tue, Dec 29, 2009 at 7:51 PM, Carl Johnson <[email protected]> wrote:
>
>> Hi,
>> without the line HUD_Camera->setRenderOrder( osg::Camera::NESTED_RENDER );
>> I get only the blue backgroundcolor and with an error.
>>
>> Thank you!
>>
>> Cheers,
>> Carl
>>
>> ------------------
>> Read this topic online here:
>> http://forum.openscenegraph.org/viewtopic.php?p=21932#21932
>>
>>
>>
>>
>>
>> _______________________________________________
>> osg-users mailing list
>> [email protected]
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>
>
>
                                                                     
                                                                     
                                                                     
                                             
/******************************************************************************\
* HUD                                                                          *
* Head-up Display in OSG.                                                      *
* Leandro Motta Barros (based on OSG examples)                                 *
\******************************************************************************/


#include <osg/PositionAttitudeTransform>
#include <osg/Group>
#include <osg/Node>
#include <osgDB/ReadFile> 
#include <osgViewer/Viewer>

#include <osgText/Font>
#include <osgText/Text>
#include <osg/MatrixTransform>
#include <osg/Geode>
#include <osg/Projection>
#include <osg/ShapeDrawable>
#include <osg/Geometry>
#include <osgGA/TrackballManipulator>
#include <osgViewer/ViewerEventHandlers>

// - CreateGeometry ------------------------------------------------------------
osg::ref_ptr<osg::Group> CreateHUD()
{
        osg::ref_ptr<osg::Group> Root( new osg::Group );


        // HUD
        osg::ref_ptr<osgText::Text> HUD_Text( new osgText::Text );
        HUD_Text->setCharacterSize( 35 );
        HUD_Text->setFont( "data/arial.ttf" );
        HUD_Text->setText( "Not so good" );
        //HUD_Text->setAxisAlignment( osgText::Text::SCREEN );
        HUD_Text->setPosition( osg::Vec3( 30.0, 30.0, 0.0 ) );
        HUD_Text->setColor( osg::Vec4( 1.0, 1.0, 0.0, 1.0 ) );

        // HUD Vertices
        osg::ref_ptr<osg::Vec3Array> HUD_Vertices( new osg::Vec3Array );
        HUD_Vertices->push_back( osg::Vec3d( 0.0, 0.0, -0.1 ) );
        HUD_Vertices->push_back( osg::Vec3d( 1024.0, 0.0, -0.1 ) );
        HUD_Vertices->push_back( osg::Vec3d( 1024.0, 200.0, -0.1 ) );
        HUD_Vertices->push_back( osg::Vec3d( 0.0, 200.0, -0.1 ) );

        // HUD Indices
        osg::ref_ptr<osg::DrawElementsUInt> HUD_Indices( new 
osg::DrawElementsUInt( osg::PrimitiveSet::POLYGON, 0 ) );
        HUD_Indices->push_back( 0 );
        HUD_Indices->push_back( 1 );
        HUD_Indices->push_back( 2 );
        HUD_Indices->push_back( 3 );

        // Hud Color
        osg::ref_ptr<osg::Vec4Array> HUD_Color(new osg::Vec4Array );
        HUD_Color->push_back( osg::Vec4( 0.8f, 0.8f, 0.8f, 0.8f) );

        // HUD Normals
        osg::ref_ptr<osg::Vec3Array> HUD_Normals( new osg::Vec3Array );
        HUD_Normals->push_back( osg::Vec3( 0.0f, 0.0f, -1.0f ) );

        // HUD Geometry
        osg::ref_ptr<osg::Geometry> HUD_Geometry( new osg::Geometry );
        HUD_Geometry->setNormalArray( HUD_Normals );
        HUD_Geometry->setNormalBinding( osg::Geometry::BIND_OVERALL );
        HUD_Geometry->addPrimitiveSet( HUD_Indices );
        HUD_Geometry->setVertexArray( HUD_Vertices );
        HUD_Geometry->setColorArray( HUD_Color );
        HUD_Geometry->setColorBinding( osg::Geometry::BIND_OVERALL );

        // HUD Renderstates
        osg::ref_ptr<osg::StateSet> HUD_StateSet( new osg::StateSet );
        HUD_StateSet->setMode( GL_BLEND, osg::StateAttribute::ON );
        HUD_StateSet->setMode( GL_DEPTH_TEST, osg::StateAttribute::OFF );
        HUD_StateSet->setMode( GL_LIGHTING,osg::StateAttribute::OFF );
        //HUD_StateSet->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
        //HUD_StateSet->setRenderBinDetails( 11, "DepthSortedBin");

        // HUD Geode
        osg::ref_ptr<osg::Geode> HUD_Geode( new osg::Geode );
        HUD_Geode->addDrawable( HUD_Geometry.get() );
        HUD_Geode->addDrawable( HUD_Text.get() );
        HUD_Geode->setStateSet( HUD_StateSet.get() );

        // HUD View
        osg::ref_ptr<osg::MatrixTransform> HUD_Transform( new 
osg::MatrixTransform );
        HUD_Transform->setMatrix( osg::Matrix::identity() );
        HUD_Transform->setReferenceFrame( 
osg::Transform::ABSOLUTE_RF_INHERIT_VIEWPOINT );
        HUD_Transform->addChild( HUD_Geode.get() );

        // HUD Projection
        /*
        osg::ref_ptr<osg::Projection> HUD_Projection( new osg::Projection );
        HUD_Projection->setMatrix( osg::Matrix::ortho2D( 0.0, 1024.0, 0.0, 
768.0 ) );
        HUD_Projection->addChild( HUD_Transform.get() );
        */

        osg::Camera* HUD_Camera( new osg::Camera );
        HUD_Camera->setProjectionMatrix( osg::Matrix::ortho2D( 0, 1280, 0, 1024 
) );
        HUD_Camera->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
        HUD_Camera->setViewMatrix( osg::Matrix::identity() );
        HUD_Camera->setClearMask( GL_DEPTH_BUFFER_BIT );
        HUD_Camera->setRenderOrder( osg::Camera::POST_RENDER);
        HUD_Camera->setAllowEventFocus( false );
        HUD_Camera->addChild( HUD_Transform.get() );

        Root->addChild( HUD_Camera );

        return Root;
}
int main (int argc, char* argv[])
{
        // Create a Producer-based viewer
        osgViewer::Viewer viewer;
        viewer.addEventHandler( new osgViewer::StatsHandler );
        viewer.setUpViewInWindow( 32, 32, 1024, 768 );
        viewer.setSceneData( CreateHUD().get() );
        viewer.setCameraManipulator(new osgGA::TrackballManipulator());
        viewer.realize();

        while( !viewer.done() )
        {
                viewer.frame();
        }

        return 0;
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to