亲爱的程序员和OpenGL黑客,
我有一个带有6个纹理的立方体贴图,按照GLKTextureLoader文档中的说明进行排序。
使用我的文件路径数组调用 [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
提前致谢!