Guardar imageRef de GLPaint crea una imagen completamente negra

Hola, estoy probando la aplicación de dibujo y tengo un problema a la hora de guardar la imagen que se dibuja. En este momento estoy muy temprano en aprender esto, pero he agregado código de: ¿Cómo obtener UIImage de EAGLView? para guardar la imagen que se dibujó.

He creado una nueva aplicación, luego visualicé un viewController que creé. En IB, he agregado una vista que es PaintingView, y una imageView se encuentra detrás de ella.

La única modificación que he hecho hasta el PaintingView hasta ahora es cambiar el fondo para borrar y establecer el fondo para borrar para que pueda mostrar una imagen detrás de él. El dibujo funciona muy bien, mi único problema es guardar.

- (void)saveImageFromGLView:(UIView *)glView {

    if(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES)
        {
            /// This IS being activated with code 0
            NSLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
    }


    int s = 1;
    UIScreen* screen = [ UIScreen mainScreen ];
    if ( [ screen respondsToSelector:@selector(scale) ] )
        s = (int) [ screen scale ];

    const int w = self.frame.size.width;
    const int h = self.frame.size.height;
    const NSInteger myDataLength = w * h * 4 * s * s;
    // allocate array and read pixels into it.
    GLubyte *buffer = (GLubyte *) malloc(myDataLength);
    glReadPixels(0, 0, w*s, h*s, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
    // gl renders "upside down" so swap top to bottom into new array.
    // there's gotta be a better way, but this works.
    GLubyte *buffer2 = (GLubyte *) malloc(myDataLength);
    for(int y = 0; y < h*s; y++)
    {
        memcpy( buffer2 + (h*s - 1 - y) * w * 4 * s, buffer + (y * 4 * w * s), w * 4 * s );
    }
    free(buffer); // work with the flipped buffer, so get rid of the original one.

    // make data provider with data.
    CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer2, myDataLength, NULL);
    // prep the ingredients
    int bitsPerComponent = 8;
    int bitsPerPixel = 32;
    int bytesPerRow = 4 * w * s;
    CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
    CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
    CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
    // make the cgimage
    CGImageRef imageRef = CGImageCreate(w*s, h*s, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
    // then make the uiimage from that
    UIImage *myImage = [ UIImage imageWithCGImage:imageRef scale:s orientation:UIImageOrientationUp ];
    UIImageWriteToSavedPhotosAlbum( myImage, nil, nil, nil );
    CGImageRelease( imageRef );
    CGDataProviderRelease(provider);
    CGColorSpaceRelease(colorSpaceRef);
    free(buffer2);    

}

Agregar el código anterior a la aplicación de ejemplo funciona bien, el problema es hacerlo en mi nueva aplicación. La única diferencia que puedo decir es que no he incluido PaintingWindow, ¿ese sería el problema?

Es como si el método saveImage no estuviera viendo los datos de los dibujos.

Respuestas a la pregunta(6)

Su respuesta a la pregunta