X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fscreen%2Fscreen-dump.cxx;h=ecea865933dae8f7a7e363bd0e5f8620f4261bde;hb=5f804cb0eb126ab7162855dad14d20eb381309c6;hp=ebde34ca362b46d9932efbc96387c1dedcbc2f3c;hpb=400c9d6a2dede85c42abb256b08c52274e7aad48;p=simgear.git diff --git a/simgear/screen/screen-dump.cxx b/simgear/screen/screen-dump.cxx index ebde34ca..ecea8659 100644 --- a/simgear/screen/screen-dump.cxx +++ b/simgear/screen/screen-dump.cxx @@ -12,28 +12,29 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Library General Public License for more details. // -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the -// Free Software Foundation, Inc., 59 Temple Place - Suite 330, -// Boston, MA 02111-1307, USA. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // $Id$ #ifdef HAVE_CONFIG_H -# include +# include #endif -#ifdef HAVE_WINDOWS_H -# include +#ifdef WIN32 +# include #endif #include #include #include -#include -#include +#include + +#include +#include #include "screen-dump.hxx" @@ -41,7 +42,7 @@ #define RGB3 3 // 3 bytes of color info per pixel #define RGBA 4 // 4 bytes of color+alpha info -void my_glWritePPMFile(const char *filename, GLubyte *buffer, int win_width, int win_height, int mode) +bool sg_glWritePPMFile(const char *filename, GLubyte *buffer, int win_width, int win_height, int mode) { int i, j, k, q; unsigned char *ibuffer; @@ -51,8 +52,9 @@ void my_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; + return false; } fprintf(fp, "P6\n# CREATOR: glReadPixel()\n%d %d\n%d\n", @@ -67,22 +69,16 @@ void my_glWritePPMFile(const char *filename, GLubyte *buffer, int win_width, int fclose(fp); free(ibuffer); - printf("wrote file (%d x %d pixels, %d bytes)\n", - win_width, win_height, RGB3*win_width*win_height); + printf("wrote file '%s' (%d x %d pixels, %d bytes)\n", + filename, win_width, win_height, RGB3*win_width*win_height); + return true; } -// dump the screen buffer to a ppm file -void my_glDumpWindow(const char *filename, int win_width, int win_height) { - GLubyte *buffer; - - 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); - 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 img(new osg::Image); + img->readPixels(0,0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE); + return osgDB::writeImageFile(*img, filename); }