sherman wilcox wrote:
> Ok. Thanks for the reply. Followup question: Is there an automagic way
> to determine what this last camera is or do I need to keep track of
> that myself?
> 
> Is it reasonable to attach a camera to the scenegraph set as the
> "last" camera just for capture purposes? I wouldn't think there would
> be much overhead incurred, but never hurts to ask.

Sherman,

I'm still learning how to fully use OSG myself, but here's the skeleton
code I wrote (based on the "osghud" and other examples).
[If anyone more experienced has any corrections/improvements to this
code, we'd all appreciate it].

This code "works for me" in my application, and will hopefully be easier
for you to get going with than the 3-styles-in-one osghud example (it
took me a few hours of testing settings and reading docs to figure out
exactly what was needed for each of the 3 display styles used in that
example).

The setRenderOrder(osg::Camera::POST_RENDER) on the HUD scene basically
makes it the "last" camera since all other scenes will be rendered
before this one.

I personally wouldn't bother with a screenshot-only camera as it will be
extra overhead and the HUD camera is basically IS that camera with some
display widgets in it.

[PS: and while the code below is from working code on my system, I did
strip out some app-specific parts for this email.  If it doesn't compile
as a result, my apologies, and I can help if the fix isn't obvious].

- Michael


// ==========

osgViewer::CompositeViewer viewer;

// Main view
{
  osg::ref_ptr<osgViewer::View> view = new osgViewer::View();
  view->setUpViewAcrossAllScreens();;
  view->setSceneData(root.get());  // root node of main scene here

  // black background for the main scene
  view->getCamera()->setClearColor(osg::Vec4(0.00, 0.00, 0.00, 1.00));

  view->addEventHandler(new osgViewer::WindowSizeHandler());
  view->addEventHandler(new osgViewer::StatsHandler());
  view->addEventHandler(new osgViewer::HelpHandler());

  viewer.addView(view.get());
}

// get window info from main view
osgViewer::Viewer::Windows windows;
viewer.getWindows(windows);
if (windows.empty()) {
  return 1;
}

// HUD view (overlaid on main view)
{
  osg::ref_ptr<osgViewer::View> view = new osgViewer::View();
  view->setSceneData(hud.get());  // root node of hud scene here

  view->getCamera()->setGraphicsContext(windows[0]);
  view->getCamera()->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
  view->getCamera()->setProjectionMatrix
    (osg::Matrix::ortho2D(0,1600,0,1200));
  view->getCamera()->setViewport(0, 0,
     windows[0]->getTraits()->width,
     windows[0]->getTraits()->height);
  view->getCamera()->setViewMatrix(osg::Matrix::identity());

  // draw this scene after the main scene (it's the "last" camera)
  view->getCamera()->setRenderOrder(osg::Camera::POST_RENDER);

  // no background (clear) so the main scene shows through
  view->getCamera()->setClearMask(GL_DEPTH_BUFFER_BIT);

  // Don't let the HUD camera grab event focus from the
  // main view's camera.
  view->getCamera()->setAllowEventFocus(false);

  // Attach your screen capture draw callback here
  drawcallback_screenshot = new DrawCallback_Screenshot("screenshot");
  view->getCamera()->setPostDrawCallback
    (drawcallback_screenshot.get());

  viewer.addView(view.get());
}

return (viewer.run());

// ==========
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to