]> git.mxchange.org Git - simgear.git/blobdiff - simgear/screen/screen-dump.cxx
canvas::Text: get maximum width (if displayed on a single line).
[simgear.git] / simgear / screen / screen-dump.cxx
index 4be5096068fdbb202c8b00064491ca8c77233dfd..6165ba835623d43f67a42779466053d9b2adf615 100644 (file)
@@ -2,82 +2,39 @@
 //
 // Contributed by Richard Kaszeta <bofh@me.umn.edu>, started October 1999.
 //
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License as
-// published by the Free Software Foundation; either version 2 of the
-// License, or (at your option) any later version.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
 //
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// General Public License for more details.
+// Library General Public License for more details.
 //
 // 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 // $Id$
 
 
 #ifdef HAVE_CONFIG_H
-#  include <config.h>
+#  include <simgear_config.h>
 #endif
 
-#ifdef HAVE_WINDOWS_H
-#  include <windows.h>                     
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
+#include <simgear/compiler.h>
 
-#include <GL/glut.h>
-#include <simgear/xgl.h>
+#include <osg/Image>
+#include <osgDB/WriteFile>
 
 #include "screen-dump.hxx"
 
 
-#define RGB  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)
-{
-    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);
-
-    fp = fopen(filename, "wb");
-    fprintf(fp, "P6\n# CREATOR: glReadPixel()\n%d %d\n%d\n",
-           win_width, win_height, UCHAR_MAX);
-    q = 0;
-    for (i = 0; i < win_height; i++)
-       for (j = 0; j < win_width; j++)
-           for (k = 0; k < RGB; 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);
-    fclose(fp);
-    free(ibuffer);
-
-    printf("wrote file (%d x %d pixels, %d bytes)\n",
-          win_width, win_height, RGB*win_width*win_height);
-}
-
-
-// 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<osg::Image> img(new osg::Image);
+  img->readPixels(0,0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE);
+  return osgDB::writeImageFile(*img, filename);
 }