Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5946399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:49:03+00:00 2026-05-22T16:49:03+00:00

I have an OpenGL ES 2 drawing app (iOS 4), so I’m retaining backing

  • 0

I have an OpenGL ES 2 drawing app (iOS 4), so I’m retaining backing in my CAEAGLLayer rather than clearing on every frame:

eaglLayer.opaque = TRUE;
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                                        [NSNumber numberWithBool:TRUE], kEAGLDrawablePropertyRetainedBacking,
                                        kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat,
                                        nil];

I have a button for saving the work to photo album with the code below. Here’s the issue. When it’s done saving and I start drawing again, the whole buffer clears and my drawing begins from scratch on a blank screen. Is there a way to prevent this? I’d like to be able to continue drawing from the same state that I just saved.

I’m running the same code to save in OpenGL ES 1 and this issue doesn’t occur there. Also, this issue is only visible on the iPhone device (3GS), not the simulator. Let me know if you have ideas. Thanks.

-(void)saveCurrentScreenToPhotoAlbum 
{
    CGRect rect = [[UIScreen mainScreen] bounds];
    int width = rect.size.width;
    int height = rect.size.height;

    NSInteger myDataLength = width * height * 4;
    GLubyte *buffer = (GLubyte *) malloc(myDataLength);
    GLubyte *buffer2 = (GLubyte *) malloc(myDataLength);
    glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

    for(int y = 0; y <height; y++) 
    {
        for(int x = 0; x <width * 4; x++) 
        {
            buffer2[(int)((height - 1 - y) * width * 4 + x)] = buffer[(int)(y * 4 * width + x)];
        }
    }
    free(buffer);

    CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer2, myDataLength, releaseData);
    int bitsPerComponent = 8;
    int bitsPerPixel = 32;
    int bytesPerRow = 4 * width;
    CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
    CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
    CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
    CGImageRef imageRef = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);

    CGColorSpaceRelease(colorSpaceRef);
    CGDataProviderRelease(provider);     

    UIImage *image = [[UIImage alloc] initWithCGImage:imageRef];    // change this to manual alloc/init instead of autorelease
    CGImageRelease(imageRef);   

    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);   // add callback for finish saving
}

// callback for CGDataProviderCreateWithData
void releaseData(void *info, const void *data, size_t dataSize) 
{

    free((void*)data);   
}

// callback for UIImageWriteToSavedPhotosAlbum
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo 
{

    [image release];     
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:49:04+00:00Added an answer on May 22, 2026 at 4:49 pm

    Answer by Anna.

    I was making another call while performing this function, which resulted in confused behavior by the buffer

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple OpenGL drawing. When the user changes the window's size, I
I have a somewhat complex data model in my iPad application (an OpenGL drawing
I have a problem when rendering cubes in OpenGL.I am drawing two cubes, one
I have a drawing app where the user can draw lines with their finger,
I have the following cylinder, I am drawing a worm in opengl and I
I have tried to convert my OpenGL application to OpenGL ES. I am drawing
I'm making something like an augmented reality app, in which I have an OpenGL
I am using OpenGL ES to perform drawing in an Android app. I want
I have an OpenGL ES2-based app which runs smoothly at 30fps on an iPad
In my opengl app, I am drawing the same polygon approximately 50k times but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.