EAGLLayer 2 CGImage/UIImage anyone ?

Nibbie
Posts: 1
Joined: 2008.11
Post: #1
I'm trying to capture my non opaque eaglView, so I can composite it together with background UIView's layers into a PNG file.
Someone suggested me using glReadPixels, till now, and I'm a novice, this is how my code looks like:

Code:
-(UIImage *) getMyEAGLLayerAsAUIIamge {
    CGRect myRect = [UIScreen mainScreen].applicationFrame;
    NSInteger myDataLength = myRect.size.width * myRect.size.height * 4;
    void *buffer = (GLubyte *) malloc(myDataLength);

//    glReadBuffer(GL_FRONT);
    glFinish();
    glPixelStorei(GL_PACK_ALIGNMENT, 4);
    
    glReadPixels(myRect.origin.x, myRect.origin.y, myRect.size.width, myRect.size.height, GL_RGB, GL_UNSIGNED_BYTE, buffer);


    NSData* myImageData = [NSData dataWithBytesNoCopy:(unsigned char const **)&buffer length:myDataLength freeWhenDone:YES];
    
    if( [UIImage respondsToSelector:@selector(imageWithData:)])
            NSLog(@"supported");  
     else    NSLog(@"unsupported");
    
    UIImage *myImage = [UIImage imageWithData:myImageData];
    if( myImage != nil) { NSLog(@"Save EAGLImage failed to bind data to a IUImage"); }

    
    return myImage;

I'm getting an empty screen though. I have actually no way of knowing that I'm doing the right things converting the data form GLubyte to something readable by CoreCraphics, or maybe I am not using glReadPixels right.
Any help would be greatly appreciated !
Quote this message in a reply
Sage
Posts: 1,234
Joined: 2002.10
Post: #2
RGB isn't a valid format for ReadPixels, in ES. See section 4.3.
Quote this message in a reply
Post Reply