Hi All,
Previously I have hinted that with osgViewer it'll be possible to
implement HUD directly in the viewer by adding a camera to the viewer
rather than adding a camera to the scene graph. I have now wired up
the osghud example to add a slave camera to osgViewer::Viewer, and a
adding a seperate View to an osgViewer::CompositeViewer. The original
HUD camera in the scene graph remains as well.
To run the different variants you can use:
osghud cow.osg // original hud Camera in the scene graph
osghud --Viewer cow.osg // place the HUD camera into the viewer as a slave
osghud --CompositeViewer cow.osg // place the HUD camera into the
viewer as a view
In each of these paths the actual Camera setup is identical - in fact
they all use the same HUD camera setup function, the only variation is
in adding the camera to the scene graph or viewer. The code from
osghud is copy and pasted at the bottom of this email.
The ability to use Camera's in the scene graph or in the viewer means
that you can place the camera where it makes most logical sense for
your app. This applies equally to HUD's as it does RTT cameras like
the ones used in osgdistortion.
As a general guide HUD probably most logical reside in the viewer
rather than a scene graph. As do high level RTT effects like
distortion correction as they have much more to do with the
constraints of the display system than effects in the scene itself.
Converserly RTT effects like shadows, reflections, overlays, impostors
are all examples where the RTT camera which is creating the effect is
closely associated with the scene itself - the viewer doesn't have
shadows but the scene does.
There is one final twist with where to stick Cameras - you can use
them directly on graphics windows, rather than in the viewer or the
scene graph. The StatsHandler and HelpHandler are both examples of
this. This type of usage still needs a bit of evolution to make it
slick.
Robert.
--
if (arguments.read("--Viewer"))
{
// construct the viewer.
osgViewer::Viewer viewer;
// create a HUD as slave camera attached to the master view.
viewer.setUpViewAcrossAllScreens();
osgViewer::Viewer::Windows windows;
viewer.getWindows(windows);
if (windows.empty()) return 1;
osg::Camera* hudCamera = createHUD();
// set up cameras to rendering on the first window available.
hudCamera->setGraphicsContext(windows[0]);
hudCamera->setViewport(0,0,windows[0]->getTraits()->width,
windows[0]->getTraits()->height);
viewer.addSlave(hudCamera, false);
// set the scene to render
viewer.setSceneData(scene.get());
return viewer.run();
}
if (arguments.read("--CompositeViewer"))
{
// construct the viewer.
osgViewer::CompositeViewer viewer;
// create the main 3D view
osgViewer::View* view = new osgViewer::View;
viewer.addView(view);
view->setSceneData(scene.get());
view->setUpViewAcrossAllScreens();;
view->setCameraManipulator(new osgGA::TrackballManipulator);
// now create the HUD camera's view
osgViewer::Viewer::Windows windows;
viewer.getWindows(windows);
if (windows.empty()) return 1;
osg::Camera* hudCamera = createHUD();
// set up cameras to rendering on the first window available.
hudCamera->setGraphicsContext(windows[0]);
hudCamera->setViewport(0,0,windows[0]->getTraits()->width,
windows[0]->getTraits()->height);
osgViewer::View* hudView = new osgViewer::View;
hudView->setCamera(hudCamera);
viewer.addView(hudView);
return viewer.run();
}
else
{
// construct the viewer.
osgViewer::Viewer viewer;
osg::ref_ptr<osg::Group> group = new osg::Group;
// add the HUD subgraph.
if (scene.valid()) group->addChild(scene.get());
group->addChild(createHUD());
// set the scene to render
viewer.setSceneData(group.get());
return viewer.run();
}
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/