亲爱的程序员和 OpenGL 黑客们,
我有一个立方体贴图,其中包含 GLKTextureLoader 文档中所写的 6 个纹理。
当使用我的文件路径数组调用[GLKTextureLoader cubeMapWithContentsOfFiles:options:error:]时, GLKTextureInfo返回一个带有关键OpenGL 错误和值1281的错误。
我试过 npot 和 pot 纹理。我正在使用的纹理上传到我的网络空间www.stefanpopp.de/cubemap
这是我当前的代码片段。我已经尝试像往常一样在立方体贴图之前加载单个纹理,并且效果很好。
破码
- (BOOL)loadTextures
{
// make sure EAGL context is active
[EAGLContext setCurrentContext:self.context];
/*
Array of textures sorted as written in apple documentation
Right(+x), Left(-x), Top(+y), Bottom(-y), Front(+z), Back(-z).
Ref: http://developer.apple.com/library/ios/#documentation/GLkit/Reference/GLKTextureLoader_ClassRef/Reference/Reference.html#//apple_ref/occ/clm/GLKTextureLoader/cubeMapWithContentsOfFiles:options:error:
*/
NSArray *texturesArray = @[
[[NSBundle mainBundle] pathForResource:@"Right" ofType:@"png"], // +x
[[NSBundle mainBundle] pathForResource:@"Left" ofType:@"png"], // -x
[[NSBundle mainBundle] pathForResource:@"Up" ofType:@"png"], // +y
[[NSBundle mainBundle] pathForResource:@"Down" ofType:@"png"], // -y
[[NSBundle mainBundle] pathForResource:@"Front" ofType:@"png"], // +z
[[NSBundle mainBundle] pathForResource:@"Back" ofType:@"png"], // -z
];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES],
GLKTextureLoaderOriginBottomLeft,
nil];
NSError *error;
// load cubemap texture with given array of file paths
self.cubemapTexture = [GLKTextureLoader cubeMapWithContentsOfFiles:texturesArray
options:options
error:&error];
// if cubemapeTexture is null, loading failed
if (nil == self.cubemapTexture) {
NSLog(@"Failure reason: %@", error.description);
NSLog(@"Error code: %i", error.code);
NSLog(@"Textures: %@", texturesArray);
NSLog(@"Error: %@", [error description]);
@throw @"Can not load cubemap textures";
} else {
NSLog(@"Loaded cubemap textures '%@'\n", self.cubemapTexture);
}
return YES;
}
错误信息输出
ERROR: The operation couldn’t be completed. (GLKTextureLoaderErrorDomain error 8.)
Failure reason: Error Domain=GLKTextureLoaderErrorDomain Code=8 "The operation couldn’t be completed.
(GLKTextureLoaderErrorDomain error 8.)" UserInfo=0x886bee0 {
GLKTextureLoaderGLErrorKey=1281,
GLKTextureLoaderErrorKey=OpenGL error
}
Error code: 8
Error loading cubemap texture (null)
Textures: (
"/ShortenPATH/Right.png",
"/ShortenPATH/Left.png",
"/ShortenPATH/Up.png",
"/ShortenPATH/Down.png",
"/ShortenPATH/Front.png",
"/ShortenPATH/Back.png"
)
Error: Error Domain=GLKTextureLoaderErrorDomain Code=8
"The operation couldn’t be completed.
(GLKTextureLoaderErrorDomain error 8.)" UserInfo=0x886bee0 {
GLKTextureLoaderGLErrorKey=1281, GLKTextureLoaderErrorKey=OpenGL error
}
*** Terminating app due to uncaught exception of class '__NSCFConstantString'
terminate called throwing an exception
提前致谢!