hello
i am trying to display an image on iphone by converting it into texture and then displaying it on the UIView.
here is the code to load an image from an UIImage object
- (void)loadImage:(UIImage *)image mipmap:(BOOL)mipmap texture:(uint32_t)texture
{
int width, height;
CGImageRef cgImage;
GLubyte *data;
CGContextRef cgContext;
CGColorSpaceRef colorSpace;
GLenum err;
if (image == nil)
{
NSLog(@"Failed to load");
return;
}
cgImage = [image CGImage];
width = CGImageGetWidth(cgImage);
height = CGImageGetHeight(cgImage);
colorSpace = CGColorSpaceCreateDeviceRGB();
// Malloc may be used instead of calloc if your cg image has dimensions equal to the dimensions of the cg bitmap context
data = (GLubyte *)calloc(width * height * 4, sizeof(GLubyte));
cgContext = CGBitmapContextCreate(data, width, height, 8, width * 4, colorSpace, kCGImageAlphaPremultipliedLast);
if (cgContext != NULL)
{
// Set the blend mode to copy. We don't care about the previous contents.
CGContextSetBlendMode(cgContext, kCGBlendModeCopy);
CGContextDrawImage(cgContext, CGRectMake(0.0f, 0.0f, width, height), cgImage);
glGenTextures(1, &(_textures[texture]));
glBindTexture(GL_TEXTURE_2D, _textures[texture]);
if (mipmap)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
else
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
if (mipmap)
glGenerateMipmapOES(GL_TEXTURE_2D);
err = glGetError();
if (err != GL_NO_ERROR)
NSLog(@"Error uploading texture. glError: 0x%04X", err);
CGContextRelease(cgContext);
}
free(data);
CGColorSpaceRelease(colorSpace);
}
The problem that i currently am facing is this code workd perfectly fine and displays the image on simulator where as on the device as seen on debugger an error is displayed i.e. Error uploading texture. glError: 0x0501
any idea how to tackle this bug.... thnx in advance 4 ur soluitons