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

Later versions OpenGL support compresses textures. You can have them being compressed by OpenGL upon uploading the texture data, or do it yourself and provide the pre-compressed data to OpenGL.

Up vote 0 down vote favorite share g+ share fb share tw.

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 8 MB of memory, which is unacceptable for an iPhone/iPad app. Could anyone tell me how I can compress the texture to reduce memory usage?

Iphone ipad opengl-es link|improve this question edited Dec 22 '10 at 16:03Brad Larson59.3k888182 asked Dec 22 '10 at 11:45nonamelive784818 69% accept rate.

I would suggest looking into on-device PowerVR texture compression, but the answer to this question would seem to indicate that that's not possible: Convert . Png to PVRTC on the iPhone. .

However, there may be a different way to achieve this. – Brad Larson Dec 22 '10 at 16:09 @BradLarson I think I'm wrong here. I think the better way is to shrink the screenshots (512 * 512) and scale it to fit the texture (1024 * 1024).

In this way, every texture is 1MB now. But I don't know how to achieve this. Any help?

– nonamelive Dec 22 '10 at 16:12.

Later versions OpenGL support compresses textures. You can have them being compressed by OpenGL upon uploading the texture data, or do it yourself and provide the pre-compressed data to OpenGL. The ARB specification for compressed texture support in OpenGL opengl.org/registry/specs/ARB/texture_co... And here's the description of one particular compression format opengl.org/registry/specs/ARB/texture_co... And specific to OpenGL ES this compression format: http://www.khronos.org/registry/gles/extensions/OES/OES_compressed_ETC1_RGB8_texture.txt.

I don't believe the older OpenGL references apply to OpenGL ES, so those probably aren't useful in this case. The iPhone specifically uses PowerVR texture compression, so I'm not sure that the last reference on Ericsson Texture Compression applies here either. – Brad Larson Dec 22 '10 at 16:07.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions