2vi*_*on2 7 iphone opengl-es objective-c ios glkit
我使用此链接中的代码来映射人脸的纹理.此代码使用GLKIT渲染图像.代码在模拟器中工作正常,但如果我在设备中运行它无法正常工作,则代码相同.以下是图像的屏幕截图,它在设备中工作,而不是在我的ipad中.
我用来加载纹理的代码:
- (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));
}
Run Code Online (Sandbox Code Playgroud)
模拟器的图像:

设备中的相同代码提供以下输出:

有什么东西我不见了?
我最终屈服并切换到 GLKTextureLoader。正如亚当提到的,它非常坚固。
这是一个可能适合您的实现:
- (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);
}
Run Code Online (Sandbox Code Playgroud)
我很快就会为 GitHub 上的项目更改它mtl2opengl......
| 归档时间: |
|
| 查看次数: |
1431 次 |
| 最近记录: |