Open Scene Graph: Render scene to image

30 Jun

OSG ships with many examples including several applications that renders the scene to image, for instance OsgAutoCapture, and OsgScreenCapture.

Whilst these applications are information rich, yet they lack sufficient conciseness and are not right to the point sometimes. It took me hours to get what I need, and for my specific task, I just need such a simple class OsgSnapshotHelper:

void Capture(osgViewer::Viewer* pViewer, std::string outputImagePath)
OsgSnapshotHelper* osh = new OsgSnapshotHelper(pViewer);
delete osh;
osh = NULL;
std::cout << Ending Capture: << outputImagePath  << std::endl;


And here is my implementation, based on OsgAutoCapture example. I wrapped it to what I need and removed all unnecessary stuff into one single class, which would be very portable then.


Example main.cpp:

extern void Capture(osgViewer::Viewer* pViewer, std::string outputImagePath);
int main(int argc, char **argv)
	auto node = osgDB::readNodeFile("C:\\SomeFolder\\cow.osg");
	osgViewer::Viewer viewer;
	viewer.setCameraManipulator(new osgGA::TrackballManipulator);		
	//viewer.addEventHandler(new OsgKeyboardEventHandler(&viewer));
	// while (!viewer.done()){	viewer.frame();		}
	Capture(&viewer, "ppp.png");
	return 0;

Download the header and cpp files from or Google Drive.


Posted by on June 30, 2014 in osg, Programming


Tags: , , , , , , ,

5 responses to “Open Scene Graph: Render scene to image

  1. Nico

    September 29, 2016 at 12:34 am

    I’m doing the same work as your post, and it’s taking me hours too.
    I would like to use your work,a s you shared it, but the link “Download the header and cpp files here.” is broken: no way for me to download it.
    Can you either check the fil (.rar), or send it to me by mail ?

    Thanks a lot !

  2. xinyustudio

    September 29, 2016 at 9:12 pm

    The link still works.

  3. Nico

    September 30, 2016 at 3:49 am

    OK. Not for me: I guess you have a account at and not me…
    Would you mind to send the .rar by mail please ?

  4. xinyustudio

    September 30, 2016 at 9:18 am

    Added google drive for your download. Please see the updated link at the tail of this blog.

  5. Nico

    September 30, 2016 at 11:42 pm

    It’s OK with google drive. Thanks 1000x !


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: