I have code which is something like this:
osgViewer::Viewer viewer;
viewer.setSceneData(scene);
viewer.setCameraManipulator( tracker.get() );
viewer.setUpViewInWindow(10,10,1024,768,0);
viewer.realize();
Now, this viewer object gives me a view of a scene which contains a vehicle model, terrain etc. I would like to get an RGB image out of this viewer, irrespective of how the data has been written into the scene.
Essentially, I want an RGB image from the viewer with no previous information as to what data is written into the scene. If the viewer shows something in a 1024*768 window, I want it as an RGB image.
If I understand you correctly, then the osg::ScreenCaptureHandler should fit your bill. It is part of the ViewerEventHandlers header located in include/osgViewer.
It is a simple event handler which, upon a key press, captures and stores an image of the current view. You can either use this or adapt it to your liking.