X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fscreen%2Fscreen-dump.cxx;h=ecea865933dae8f7a7e363bd0e5f8620f4261bde;hb=33970663435dd1a12941b017739285341205acf4;hp=8e23b8f2dc9d8d6e81636eaed839bc9d29be9066;hpb=80bcaa49e6dd5666432946dc7c524a7de3f26ef4;p=simgear.git diff --git a/simgear/screen/screen-dump.cxx b/simgear/screen/screen-dump.cxx index 8e23b8f2..ecea8659 100644 --- a/simgear/screen/screen-dump.cxx +++ b/simgear/screen/screen-dump.cxx @@ -23,11 +23,7 @@ # include #endif -#if defined(__CYGWIN__) /* && !defined(USING_X) */ -#define WIN32 -#endif - -#if defined(WIN32) /* MINGW and MSC predefine WIN32 */ +#ifdef WIN32 # include #endif @@ -37,7 +33,8 @@ #include -#include SG_GL_H +#include +#include #include "screen-dump.hxx" @@ -55,6 +52,7 @@ bool sg_glWritePPMFile(const char *filename, GLubyte *buffer, int win_width, int ibuffer = (unsigned char *) malloc(win_width*win_height*RGB3); if ( (fp = fopen(filename, "wb")) == NULL ) { + free(ibuffer); printf("Warning: cannot open %s\n", filename); return false; } @@ -77,21 +75,10 @@ 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, returns true on success 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); + return osgDB::writeImageFile(*img, filename); }