A Head Up Display, or HUD, is a 2D user interface overlaid on the main 3D view. A HUD is traditionally used of status information, icons, buttons and so on.

Because a HUD is typically 2D rather than 3D, it makes sense to render it using an orthographic rather than perspective projection. In OpenSceneGraph, the easiest way to do this is to use a new osg::Camera. The camera is configured to have:

  • Orthographic projection. You can choose the width and height of your HUD.
  • Absolute reference frame, so it is fixed to the screen and does not move with the 3D view.
  • Rendered last (POST_RENDER) with cleared depth, and no depth testing, so it appears above all other objects
  • No lighting.

You can of course configure it differently, but these settings work well for standard HUDs.

osg::Camera* hudCamera = new osg::Camera();
hudCamera->setProjectionMatrixAsOrtho2D(0, hudWidth, 0, hudHeight);
hudCamera->setViewMatrix(osg::Matrix::identity());
hudCamera->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
hudCamera->setRenderOrder(osg::Camera::POST_RENDER);
hudCamera->setClearMask(GL_DEPTH_BUFFER_BIT);
hudCamera->getOrCreateStateSet()->setMode(GL_LIGHTING, GL_FALSE);
hudCamera->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, GL_FALSE);

root->addChild(hudCamera);