X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fscreen%2Fscreen-dump.cxx;h=ce4b5c45ff1e5bcb9fa8718382c1a6ba9144b80c;hb=dc09a50472890ac706d3c76d8af34cc3682ada0c;hp=e986d61b9aee4b513216d54f7824a5a728044e9d;hpb=b0134a377ec703e82ed5e3f9dd18882122c1a11a;p=simgear.git diff --git a/simgear/screen/screen-dump.cxx b/simgear/screen/screen-dump.cxx index e986d61b..ce4b5c45 100644 --- a/simgear/screen/screen-dump.cxx +++ b/simgear/screen/screen-dump.cxx @@ -21,38 +21,43 @@ #ifdef HAVE_CONFIG_H -# include +# include #endif -#ifdef HAVE_WINDOWS_H -# include +#if defined(__CYGWIN__) /* && !defined(USING_X) */ +#define WIN32 +#endif + +#if defined(WIN32) /* MINGW and MSC predefine WIN32 */ +# include #endif #include #include #include -#include -#include +#include + +#include SG_GL_H #include "screen-dump.hxx" -#define RGB 3 // 3 bytes of color info per pixel +#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; FILE *fp; int pixelSize = mode==GL_RGBA?4:3; - ibuffer = (unsigned char *) malloc(win_width*win_height*RGB); + ibuffer = (unsigned char *) malloc(win_width*win_height*RGB3); if ( (fp = fopen(filename, "wb")) == NULL ) { printf("Warning: cannot open %s\n", filename); - return; + return false; } fprintf(fp, "P6\n# CREATOR: glReadPixel()\n%d %d\n%d\n", @@ -60,21 +65,23 @@ void my_glWritePPMFile(const char *filename, GLubyte *buffer, int win_width, int q = 0; for (i = 0; i < win_height; i++) for (j = 0; j < win_width; j++) - for (k = 0; k < RGB; k++) + for (k = 0; k < RGB3; k++) ibuffer[q++] = (unsigned char) *(buffer + (pixelSize*((win_height-1-i)*win_width+j)+k)); - fwrite(ibuffer, sizeof(unsigned char), RGB*win_width*win_height, fp); + fwrite(ibuffer, sizeof(unsigned char), RGB3*win_width*win_height, fp); fclose(fp); free(ibuffer); printf("wrote file (%d x %d pixels, %d bytes)\n", - win_width, win_height, RGB*win_width*win_height); + 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) { +bool sg_glDumpWindow(const char *filename, int win_width, int win_height) { GLubyte *buffer; + bool result; buffer = (GLubyte *) malloc(win_width*win_height*RGBA); @@ -82,7 +89,10 @@ void my_glDumpWindow(const char *filename, int win_width, int win_height) { glFinish(); glReadPixels(0, 0, win_width, win_height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); - my_glWritePPMFile( filename, buffer, win_width, win_height, GL_RGBA ); + result = sg_glWritePPMFile( filename, buffer, win_width, win_height, + GL_RGBA ); free(buffer); + + return result; }