Hi,
here is my Code:
Function to create the HUD:
Code:
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( 25 );
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, 1.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. ) );
HUD_Vertices->push_back( osg::Vec3d( 1024.0, 0.0, 0. ) );
HUD_Vertices->push_back( osg::Vec3d( 1024.0, 200.0, 0. ) );
HUD_Vertices->push_back( osg::Vec3d( 0.0, 200.0, 0. ) );
// 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->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() );
Root->addChild( HUD_Projection.get() );
return Root;
}
My Main function:
Code:
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 viewer.run();
return 0;
}
After compiling and testing i dont see the HUD on the Screen. This is the
example Code from the osg Homepage and it doesnt work.
Please help me to find my mistake.
Thanks a lot.
Cheers,
Carl
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=21900#21900
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org