0

Been dabbling with OpenGLES and having varying levels of success. My current problem is trying to load a .obj file. I found a great GLOBJLoader that I've been to implement in my current project but am not quite there yet.

Here is my code

- (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;
    }
}
}

The createFrameBuffer() method is obviously to create the frame buffer, the checkFrameBuffer() is simply to help debug and outputs the state of the frame buffer after each step I take.

The output I get from this is:

  1. Check 1
  2. Error code: 8cdd -->
  3. Complete
  4. Check 2
  5. Error code: 8cdd -->
  6. Complete
  7. Check 3
  8. Error code: 8cd7 -->
  9. Incomplete: Missing Attachment
  10. Check 4
  11. Error code: 8cd7 -->
  12. Incomplete: Missing Attachment
  13. Check 5
  14. Error code: 8cd7 -->
  15. Incomplete: Missing Attachment
  16. Check 6
  17. Error code: 8cd6 -->
  18. Incomplete: Attachment
  19. Check 7
  20. Error code: 8cd6 -->
  21. Incomplete: Attachment
  22. Check 8
  23. Error code: 8cd6 -->
  24. Incomplete: Attachment
  25. Check 9
  26. Error code: 8cd6 -->
  27. Incomplete: Attachment
  28. Check 10
  29. Error code: 8cd6 -->
  30. Incomplete: Attachment
  31. Check 11
  32. Error code: 8cd6 -->
  33. Incomplete: Attachment
  34. Check 12
  35. Error code: 8cd6 -->
  36. Incomplete: Attachment

These issues are stopping it from working and I am completely baffled. It should be said that I don't really know much about OpenGL, I've just been patching things together and trying to learn as I go, but I did run through Jeff Lamarche's "OpenGLES From the Ground Up" so know small amounts.

Any help would be massively appreciated and if you need more information, please don't hesitate to ask!

Thanks,

Matt

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Matthew Hallatt
  • 1,310
  • 12
  • 24

1 Answers1

3

Are you setting your context at some point before this by using this:

[EAGLContext setCurrentContext:context];

Don't bother checking your framebuffer status until after you've attached everything. Only then will it register as complete.

The following is code that I've used for setting up OpenGL ES 1.1 (given the OES suffix I see in your code) framebuffers with a depth buffer:

    [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;
    }

One difference that leaps out at me is that you're feeding in the framebuffer instead of the render buffer in glFramebufferRenderbufferOES(). That might be the source of your problems. Also, you're explicitly setting the FBO size in pixels, rather than grabbing that size from your view's layer, and I don't know if you want to do that.

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
  • Where are you getting the &backingWidth and &backingHeight from? I've tried accessing mine through my GLView (&glView.backingWidth) and it gives the error, "Address of property expression requested". I have no idea why or what it means. And if I do try to just hardcode GLint's, the framebuffer check comes back false. I've copied your code in to my "createFrameBuffer" method but no success :/ – Matthew Hallatt May 24 '12 at 10:01
  • @MatthewHallatt They are merely GLuint properties of my controller, and could be called anything you like. Note that I use `glGetRenderbufferParameterivOES()` to read these values in the above code, which is how I know the pixel width and height of the layer this OpenGL ES framebuffer is attached to. I then use them afterward whereever I need to know this framebuffer's size. – Brad Larson May 24 '12 at 14:28
  • So the "glGetRenderbufferParameterivOES" is to retrieve the size of the view? I thought it was to set it! :D – Matthew Hallatt May 24 '12 at 15:56
  • @MatthewHallatt - Notice the `glGet` prefix. That always indicates pulling something from OpenGL ES. Also, when you pass something by reference into one of these functions, that's a good indication that its value might be altered by the function in some way. – Brad Larson May 24 '12 at 15:59
  • Ok. I've now declared backing width and height in my header file and set them as properties: GLuint backingWidth, backingHeight; (at)property (nonatomic) GLuint backingWidth; (at)property (nonatomic) GLuint backingHeight; Then synthesized them and used them in the same way as yours in the glGet, but it gives the error, "No matching function for call to 'glGetRenderbufferParameterivOES'", any ideas? – Matthew Hallatt May 24 '12 at 16:04
  • @MatthewHallatt - You've imported all of the OpenGL ES headers? Such as `#import ` and `#import ` ? – Brad Larson May 24 '12 at 16:09
  • Turns out I hadn't! But that hasn't fixed the error unfortunately :/ I have imported '', '', '' and '' and its still gives the issue – Matthew Hallatt May 24 '12 at 16:14
  • So I fixed the problem, but not sure if its a proper fix or just a work around that might not help...in my header file, I changed the type of backingWidth and backingHeight from GLuint to GLint – Matthew Hallatt May 24 '12 at 16:28
  • @MatthewHallatt - I was mistaken about `GLuint`. They're actually `GLint` in the code I have here, so I must have mixed that up with another parameter type. Passing a slightly different type in by reference might have irritated the compiler, because these are just unsigned and signed int values. – Brad Larson May 24 '12 at 16:30
  • Ok, but it's still unfortunately saying that the GL_FRAMEBUFFER_OES is incomplete! – Matthew Hallatt May 24 '12 at 16:33
  • @MatthewHallatt - Then you must be doing something wrong outside of this code, like having a 0-size view or not properly initializing an OpenGL ES 1.1 context (remembering to not set up a 2.0 one by mistake). The above code comes from [a shipping application](http://www.sunsetlakesoftware.com/molecules) (code available at that link) and I've used something similar in [this sample application](http://www.sunsetlakesoftware.com/sites/default/files/CubeExample.zip). This code properly sets up a framebuffer, so your problem is now elsewhere. – Brad Larson May 24 '12 at 16:39
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/11749/discussion-between-matthew-hallatt-and-brad-larson) – Matthew Hallatt May 25 '12 at 15:18