一直涉足 OpenGLES 并取得了不同程度的成功。我当前的问题是尝试加载 .obj 文件。我发现了一个很棒的GLOBJLoader,我一直在我当前的项目中实现它,但还没有完全实现。
这是我的代码
- (void)createFramebuffer
{
glGenFramebuffersOES(1, &viewFrameBuffer);
NSLog(@"Check 1");
[self checkFrameBuffer];
glGenRenderbuffersOES(1, &viewRenderBuffer);
NSLog(@"Check 2");
[self checkFrameBuffer];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFrameBuffer);
NSLog(@"Check 3");
[self checkFrameBuffer];
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderBuffer);
NSLog(@"Check 4");
[self checkFrameBuffer];
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer];
NSLog(@"Check 5");
[self checkFrameBuffer];
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewFrameBuffer);
NSLog(@"Check 6");
[self checkFrameBuffer];
GLint wide = 320;
GLint high = 480;
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &wide);
NSLog(@"Check 7");
[self checkFrameBuffer];
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &high);
NSLog(@"Check 8");
[self checkFrameBuffer];
if(USE_DEPTH_BUFFER)
{
glGenRenderbuffersOES(1, &depthRenderBuffer);
NSLog(@"Check 9");
[self checkFrameBuffer];
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderBuffer);
NSLog(@"Check 10");
[self checkFrameBuffer];
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, glWidth, glHeight);
NSLog(@"Check 11");
[self checkFrameBuffer];
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderBuffer);
NSLog(@"Check 12");
[self checkFrameBuffer];
}
}
-(void)checkFrameBuffer
{
GLuint returned = (glCheckFramebufferStatus(GL_FRAMEBUFFER_OES));
if(returned != GL_FRAMEBUFFER_COMPLETE_OES)
{
NSLog(@"Error code: %x -->", returned);
switch (returned) {
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_OES:
NSLog(@"Incomplete: Dimensions");
break;
case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES:
NSLog(@"Incomplete: Formats");
break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_OES:
NSLog(@"Incomplete: Missing Attachment");
break;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES:
NSLog(@"Incomplete: Attachment");
break;
default:
NSLog(@"Complete");
break;
}
}
}
createFrameBuffer() 方法显然是为了创建帧缓冲区,而 checkFrameBuffer() 只是为了帮助调试并在我执行每一步后输出帧缓冲区的状态。
我从中得到的输出是:
- 检查 1
- 错误代码:8cdd -->
- 完全的
- 检查 2
- 错误代码:8cdd -->
- 完全的
- 检查 3
- 错误代码:8cd7 -->
- 不完整:缺少附件
- 检查 4
- 错误代码:8cd7 -->
- 不完整:缺少附件
- 检查 5
- 错误代码:8cd7 -->
- 不完整:缺少附件
- 检查 6
- 错误代码:8cd6 -->
- 不完整:附件
- 检查 7
- 错误代码:8cd6 -->
- 不完整:附件
- 检查 8
- 错误代码:8cd6 -->
- 不完整:附件
- 检查 9
- 错误代码:8cd6 -->
- 不完整:附件
- 检查 10
- 错误代码:8cd6 -->
- 不完整:附件
- 检查 11
- 错误代码:8cd6 -->
- 不完整:附件
- 检查 12
- 错误代码:8cd6 -->
- 不完整:附件
这些问题正在阻止它工作,我完全感到困惑。应该说我对 OpenGL 的了解并不多,我只是在拼凑一些东西并尝试边做边学,但我确实浏览了Jeff Lamarche 的“OpenGLES From the Ground Up”,所以了解的很少。
任何帮助将不胜感激,如果您需要更多信息,请随时询问!
谢谢,
马特