I am taking a picture trough the camera and I want to change the format of it to make it OpenGL ES 2.0 texture compatible.
First I get the picture and I resize it (making it a power of 2 just in case):
UIImage *newImage = [self imageWithImage:imgName scaledToSize:CGSizeMake(100, 144)];
Then I change the format from jpeg (which i think its the iphone's default format) to png:
NSData *test = UIImagePNGRepresentation(newImage);
UIImage *converted = [[UIImage alloc] initWithData:test];
Last I create my context and draw into it:
GLubyte * spriteData = (GLubyte *) calloc(width*height*4, sizeof(GLubyte));
CGContextRef spriteContext = CGBitmapContextCreate(spriteData, width, height, 8, width*4,
CGImageGetColorSpace(spriteImage), kCGImageAlphaPremultipliedLast);
CGContextDrawImage(spriteContext, CGRectMake(0, 0, width, height), spriteImage);
CGContextRelease(spriteContext);
And i can just add it the open GL buffer after this, unfortunately its not working (Only black appears), im pretty sure its because of the image format because if i do the exact same proceadure with another image which i already know it works then everything goes smoothly.
I did some research and it might be something to do with the color depth in my image, since i need 4 bits per pixel to render in opengl texture (4,4,4,4).
Internal Format: RGBA, External Format: RGBA, Type: UNSIGNED BYTE, Bytes per Pixel: 4.
So my question is, how do i change this png from whatever depth it has to the scheme i need?
PD: If anyone knows a different way to load an image into opengl please let me know!
Thanks!