How Can I Compress Texture in OpenGL on iPhone/iPad?

Posted by nonamelive on Stack Overflow See other posts from Stack Overflow or by nonamelive
Published on 2010-12-22T11:45:30Z Indexed on 2010/12/22 14:54 UTC
Read the original article Hit count: 260

Filed under:
|
|
|
|

Hi,

I'm making an iPad app which needs OpenGL to do a flip animation. I have a front image texture and a back image texture. Both the two textures are screenshots.

// Capture an image of the screen
UIGraphicsBeginImageContext(view.bounds.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

// Allocate some memory for the texture
GLubyte *textureData = (GLubyte*)calloc(maxTextureSize*4, maxTextureSize);

// Create a drawing context to draw image into texture memory
CGContextRef textureContext = CGBitmapContextCreate(textureData, maxTextureSize, maxTextureSize, 8, maxTextureSize*4, CGImageGetColorSpace(image.CGImage), kCGImageAlphaPremultipliedLast);
CGContextDrawImage(textureContext, CGRectMake(0, maxTextureSize-size.height, size.width, size.height), image.CGImage);
CGContextRelease(textureContext);
// ...done creating the texture data

[EAGLContext setCurrentContext:context];

glGenTextures(1, &textureToView);
glBindTexture(GL_TEXTURE_2D, textureToView);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, maxTextureSize, maxTextureSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData);

// free texture data which is by now copied into the GL context
free(textureData);

Each of the texture takes up about 8MB memory, which is unacceptable for an iPhone/iPad app. Could anyone tell me how can I compress the texture to reduce the memory. I'm a complete newbie to OpenGL.

Any help would be appreciated!

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c