GLKit中的纹理映射不仅适用于设备 [英] Texture mapping in GLKit is not working only in devices
问题描述
我使用此链接中的代码来映射人脸的纹理。此代码使用 GLKIT 来渲染图像。代码在模拟器中工作正常,但如果我在设备中运行它无法正常工作,则代码相同。下面是它在设备中工作的图像的屏幕截图,而不是在我的ipad中。
I used the code in this link to map textures of human faces. This code uses GLKIT to render the images. Code works fine in simulator but the same code if I run in device its not working. The below are the screen shots of the images where it works in device and not in my ipad.
我用来加载纹理的代码:
Code I used to Load Texture:
- (void)loadTexture:(UIImage *)textureImage
{
glGenTextures(1, &_texture);
glBindTexture(GL_TEXTURE_2D, _texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
CGImageRef cgImage = textureImage.CGImage;
float imageWidth = CGImageGetWidth(cgImage);
float imageHeight = CGImageGetHeight(cgImage);
CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider(cgImage));
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageWidth, imageHeight, 0, GL_RGBA,
GL_UNSIGNED_BYTE, CFDataGetBytePtr(data));
}
模拟器的图像:
相同的代码在设备中提供以下输出:
The same code in device gives the following output:
我有什么东西不见了?
推荐答案
我最后陷入困境并切换到GLKTextureLoader。正如亚当提到的那样,它非常坚固。
I finally caved in and switched to GLKTextureLoader. As Adam mentions, it's pretty sturdy.
这是一个可能适合你的实现:
Here's an implementation which might work for you:
- (void)loadTexture:(NSString *)fileName
{
NSDictionary* options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES],
GLKTextureLoaderOriginBottomLeft,
nil];
NSError* error;
NSString* path = [[NSBundle mainBundle] pathForResource:fileName ofType:nil];
GLKTextureInfo* texture = [GLKTextureLoader textureWithContentsOfFile:path options:options error:&error];
if(texture == nil)
{
NSLog(@"Error loading file: %@", [error localizedDescription]);
}
glBindTexture(GL_TEXTURE_2D, texture.name);
}
我会更改 mtl2opengl
很快就会在GitHub上投资......
I'll change it for the mtl2opengl
project on GitHub soon...
这篇关于GLKit中的纹理映射不仅适用于设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!