]> git.mxchange.org Git - simgear.git/commitdiff
Update the screen-dump code to use osgDB, and hence write out files in more common...
authorjmt <jmt>
Tue, 6 Oct 2009 20:05:46 +0000 (20:05 +0000)
committerTim Moore <timoore@redhat.com>
Wed, 7 Oct 2009 06:20:50 +0000 (08:20 +0200)
simgear/screen/screen-dump.cxx
simgear/screen/screen-dump.hxx

index dc5ba7bd56eb0c9310ceb620b5b0e4c8db5bb7ea..e4e97106b12934ab94fa15a2885f1ff62607fbb9 100644 (file)
@@ -37,7 +37,8 @@
 
 #include <simgear/compiler.h>
 
-#include <osg/GL>
+#include <osg/Image>
+#include <osgDB/WriteFile>
 
 #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<osg::Image> img(new osg::Image);
+  img->readPixels(0,0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE);
+  osgDB::writeImageFile(*img, filename);
+  return true;
 }
 
index 25a4c1967222224f1b191af780654a3d94cd7558..375f5398042b6c5ff7b3d653a5694ec2b1190049 100644 (file)
 //
 // $Id$
 
+#ifndef SG_SCREEN_DUMP_HXX
+#define SG_SCREEN_DUMP_HXX
+
 #include <simgear/compiler.h>
 
 #include <osg/GL>
 
 /**
- * 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