涉足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()只是帮助调试并在每个步骤后输出帧缓冲区的状态。
我得到的输出是:
这些问题使它停止工作,我感到非常困惑。应该说我对OpenGL并不是很了解,我只是在一起修补东西并试着去学习,但我确实经历了Jeff Lamarche's "OpenGLES From the Ground Up"所以知道少量。
任何帮助都会受到大力赞赏,如果您需要更多信息,请不要犹豫!
谢谢,
马特
答案 0 :(得分:3)
您是否在此之前的某个时刻设置了上下文:
[EAGLContext setCurrentContext:context];
在连接完所有内容之前,请不要费心检查帧缓冲状态。只有这样才能注册完成。
以下是我用于设置OpenGL ES 1.1的代码(给出我在代码中看到的OES后缀)带有深度缓冲区的帧缓冲区:
[EAGLContext setCurrentContext:context];
glGenFramebuffersOES(1, &viewFramebuffer);
glGenRenderbuffersOES(1, &viewRenderbuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:glLayer];
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
glGenRenderbuffersOES(1, &viewDepthBuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewDepthBuffer);
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, viewDepthBuffer);
if(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES)
{
return;
}
向我跳出的一个区别是,你正在使用帧缓冲而不是glFramebufferRenderbufferOES()
中的渲染缓冲区。这可能是你问题的根源。此外,您明确设置FBO大小(以像素为单位),而不是从视图的图层中获取该大小,我不知道您是否要这样做。