]> git.mxchange.org Git - simgear.git/blobdiff - simgear/screen/screen-dump.cxx
Add another subsystem group.
[simgear.git] / simgear / screen / screen-dump.cxx
index 27c6e9bc8b8666f4fbfd87d43ac9291b6346b522..ecea865933dae8f7a7e363bd0e5f8620f4261bde 100644 (file)
 // 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$
 
 #  include <simgear_config.h>
 #endif
 
-#ifdef HAVE_WINDOWS_H
-#  include <windows.h>                     
+#ifdef WIN32
+# include <windows.h>
 #endif
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <limits.h>
 
-#include GLUT_H
+#include <simgear/compiler.h>
+
+#include <osg/Image>
+#include <osgDB/WriteFile>
 
 #include "screen-dump.hxx"
 
@@ -50,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;
     }
@@ -66,27 +69,16 @@ bool sg_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
+// 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);
 }