Port image_save to GLES 1.1
authorAlberto Mardegan <mardy@users.sourceforge.net>
Wed, 13 Jul 2011 07:20:32 +0000 (10:20 +0300)
committerAlberto Mardegan <mardy@users.sourceforge.net>
Wed, 13 Jul 2011 07:20:32 +0000 (10:20 +0300)
GL_RGB in not supported by glReadPixels().

share/image.c

index b63cb66..fd35ac4 100644 (file)
@@ -59,23 +59,23 @@ void image_snap(const char *filename)
 
         png_set_write_fn(writep, filep, fs_png_write, fs_png_flush);
         png_set_IHDR(writep, infop, w, h, 8,
-                     PNG_COLOR_TYPE_RGB,
+                     PNG_COLOR_TYPE_RGB_ALPHA,
                      PNG_INTERLACE_NONE,
                      PNG_COMPRESSION_TYPE_DEFAULT,
                      PNG_FILTER_TYPE_DEFAULT);
 
         /* Allocate the pixel buffer and copy pixels there. */
 
-        if ((p = (unsigned char *) malloc(w * h * 3)))
+        if ((p = (unsigned char *) malloc(w * h * 4)))
         {
-            glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, p);
+            glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, p);
 
             /* Allocate and initialize the row pointers. */
 
             if ((bytep = (png_bytep *) png_malloc(writep, h * sizeof (png_bytep))))
             {
                 for (i = 0; i < h; ++i)
-                    bytep[h - i - 1] = (png_bytep) (p + i * w * 3);
+                    bytep[h - i - 1] = (png_bytep) (p + i * w * 4);
 
                 png_set_rows (writep, infop, bytep);