]> git.mxchange.org Git - simgear.git/blobdiff - simgear/screen/screen-dump.cxx
Add another subsystem group.
[simgear.git] / simgear / screen / screen-dump.cxx
index dc5ba7bd56eb0c9310ceb620b5b0e4c8db5bb7ea..ecea865933dae8f7a7e363bd0e5f8620f4261bde 100644 (file)
 #  include <simgear_config.h>
 #endif
 
-#if defined(__CYGWIN__)  /* && !defined(USING_X) */
-#define WIN32
-#endif
-
-#if defined(WIN32)  /* MINGW and MSC predefine WIN32 */
+#ifdef WIN32
 # include <windows.h>
 #endif
 
@@ -37,7 +33,8 @@
 
 #include <simgear/compiler.h>
 
-#include <osg/GL>
+#include <osg/Image>
+#include <osgDB/WriteFile>
 
 #include "screen-dump.hxx"
 
@@ -78,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<osg::Image> img(new osg::Image);
+  img->readPixels(0,0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE);
+  return osgDB::writeImageFile(*img, filename);
 }