From: jmt Date: Tue, 6 Oct 2009 20:05:46 +0000 (+0000) Subject: Update the screen-dump code to use osgDB, and hence write out files in more common... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e5fac0a01deec74b307cdd5666ff9a14a323e953;p=simgear.git Update the screen-dump code to use osgDB, and hence write out files in more common formats (PNG, JPEG, etc). The PPM writing code is retained for the moment, in case someone other than FG is relying upon it. --- diff --git a/simgear/screen/screen-dump.cxx b/simgear/screen/screen-dump.cxx index dc5ba7bd..e4e97106 100644 --- a/simgear/screen/screen-dump.cxx +++ b/simgear/screen/screen-dump.cxx @@ -37,7 +37,8 @@ #include -#include +#include +#include #include "screen-dump.hxx" @@ -78,21 +79,11 @@ bool sg_glWritePPMFile(const char *filename, GLubyte *buffer, int win_width, int } -// dump the screen buffer to a ppm file +// dump the screen buffer to a png file bool sg_glDumpWindow(const char *filename, int win_width, int win_height) { - GLubyte *buffer; - bool result; - - buffer = (GLubyte *) malloc(win_width*win_height*RGBA); - - // read window contents from color buffer with glReadPixels - glFinish(); - glReadPixels(0, 0, win_width, win_height, - GL_RGBA, GL_UNSIGNED_BYTE, buffer); - result = sg_glWritePPMFile( filename, buffer, win_width, win_height, - GL_RGBA ); - free(buffer); - - return result; + osg::ref_ptr img(new osg::Image); + img->readPixels(0,0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE); + osgDB::writeImageFile(*img, filename); + return true; } diff --git a/simgear/screen/screen-dump.hxx b/simgear/screen/screen-dump.hxx index 25a4c196..375f5398 100644 --- a/simgear/screen/screen-dump.hxx +++ b/simgear/screen/screen-dump.hxx @@ -21,12 +21,15 @@ // // $Id$ +#ifndef SG_SCREEN_DUMP_HXX +#define SG_SCREEN_DUMP_HXX + #include #include /** - * Dump the screen buffer to a ppm file. + * Dump the screen buffer to a PNG file. * @param filename name of file * @param win_width width of our opengl window * @param win_height height of our opengl window @@ -44,3 +47,5 @@ bool sg_glDumpWindow( const char *filename, int win_width, int win_height ); */ bool sg_glWritePPMFile( const char *filename, GLubyte *buffer, int win_width, int win_height, int mode); + +#endif // of SG_SCREEN_DUMP_HXX