Я пытаюсь отобразить изображение на iphone, преобразовав его в текстуру, а затем отобразив его в UIView.
вот код для загрузки изображения из объекта UIImage
- (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);
}
Проблема, с которой я сталкиваюсь в настоящее время, заключается в том, что этот код работает отлично и отображает изображение на симуляторе, где, как на устройстве, как видно на отладчике, отображается ошибка, т.е. ошибка: 0x0501
есть идеи, как справиться с этой ошибкой ....
спасибо заранее 4 твоих решения