+ /* Allocate the pixel buffer and copy pixels there. */
+
+ if ((p = (unsigned char *) malloc(w * h * 4)))
+ {
+ glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, p);
+
+ /* Allocate and initialize the row pointers. */
+
+ if ((bytep = png_malloc(writep, h * sizeof (png_bytep))))
+ {
+ for (i = 0; i < h; ++i)
+ bytep[h - i - 1] = (png_bytep) (p + i * w * 3);