Just to tie up loose ends.
I managed to get the simple HUD working. I think I misunderstood how things
were working before. The HUD works great now with and osg::projection object.
I created a seperate class to handle to creation of the HUD and a getter method
for the projection
Code:
void HeadsUpDisplay::initHUD()
{
projection = new osg::Projection();
HUDgeode = new osg::Geode();
osg::ref_ptr<osg::MatrixTransform> HUDModelViewMatrix = new
osg::MatrixTransform();
HUDModelViewMatrix->setMatrix(osg::Matrix::identity());
HUDModelViewMatrix->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
//TODO: Make Ortho2D screen size dynamic based on users screen res.
projection->setMatrix(osg::Matrix::ortho2D(0, 1280, 0, 1024));
projection->addChild(HUDModelViewMatrix);
initHUDGeometry();
initHUDStateSet();
HUDModelViewMatrix->addChild(HUDgeode);
}
void HeadsUpDisplay::initHUDStateSet()
{
osg::ref_ptr<osg::StateSet> HUDStateSet = new osg::StateSet();
HUDgeode->setStateSet(HUDStateSet);
HUDStateSet->setMode(GL_BLEND, osg::StateAttribute::ON);
HUDStateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
HUDStateSet->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
HUDStateSet->setRenderBinDetails(11, "RenderBin");
}
void HeadsUpDisplay::initHUDGeometry()
{
osg::ref_ptr<osg::Geometry> HUDBackgroundGeometry = new osg::Geometry();
osg::Vec3Array* HUDBackgroundVertices = new osg::Vec3Array;
HUDBackgroundVertices->push_back(osg::Vec3(1280.0f * 0.75f, 0, -1));
HUDBackgroundVertices->push_back(osg::Vec3(1280, 0, -1));
HUDBackgroundVertices->push_back(osg::Vec3(1280, 1024, -1));
HUDBackgroundVertices->push_back(osg::Vec3(1280.0f * 0.75f, 1024, -1));
osg::Vec4Array* HUDcolors = new osg::Vec4Array;
HUDcolors->push_back(osg::Vec4(0.459f, 0.765f, 0.431f, 0.3f));
osg::Vec2Array* texcoords = new osg::Vec2Array(4);
(*texcoords)[0].set(0.0f, 0.0f);
(*texcoords)[1].set(1.0f, 0.0f);
(*texcoords)[2].set(1.0f, 1.0f);
(*texcoords)[3].set(0.0f, 1.0f);
HUDBackgroundGeometry->setTexCoordArray(0, texcoords);
osg::Vec3Array* HUDnormals = new osg::Vec3Array;
HUDnormals->push_back(osg::Vec3(0.0f, 0.0f, 0.0f));
HUDBackgroundGeometry->setNormalArray(HUDnormals);
HUDBackgroundGeometry->setNormalBinding(osg::Geometry::BIND_OVERALL);
HUDBackgroundGeometry->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0,
4));
HUDBackgroundGeometry->setVertexArray(HUDBackgroundVertices);
HUDBackgroundGeometry->setColorArray(HUDcolors);
HUDBackgroundGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);
HUDgeode->addDrawable(HUDBackgroundGeometry);
}
osg::Projection* HeadsUpDisplay::getHUD()
{
return projection;
}
Hope this helps :)
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=61590#61590
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org