- // read window contents from color buffer with glReadPixels
- glFinish();
- glReadPixels(0, 0, win_width, win_height,
- GL_RGBA, GL_UNSIGNED_BYTE, buffer);
- my_glWritePPMFile( filename, buffer, win_width, win_height, GL_RGBA );
- free(buffer);
+// dump the screen buffer to a png file, returns true on success
+bool sg_glDumpWindow(const char *filename, int win_width, int win_height) {
+ osg::ref_ptr<osg::Image> img(new osg::Image);
+ img->readPixels(0,0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE);
+ return osgDB::writeImageFile(*img, filename);