I am trying to add a GLKView to a scroll view without success.
At the moment, my drawing code simply colours the background red, but before it even gets to do that it throws the error 'Failed to make complete framebuffer object 8cd6' error. I have managed to get the exact same thing working fine by drawing OpenGL into a standard UIView, but as soon as you switch it for a GLKView it always throws the error.
Here's how my scroll view is initialised in AppDelegate.m:
ScrollView *scroll = [[ScrollView alloc] init];
[[self window] setRootViewController:scroll];
And then in my ScrollView.m itself there's the following:
CGRect screenRect;
float screenWidth = 1920;
float screenHeight = 1280;
UIScrollView *scrollView;
GLKView *glkView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Custom initialization
}
return self;
}
-(void)loadView
{
// initialise the view's size parameters
screenRect.size.width = screenWidth;
screenRect.size.height = screenHeight;
// init the scrollview with the new screen rect
scrollView = [[UIScrollView alloc] initWithFrame:screenRect];
// set the delegate as itself
[scrollView setDelegate:self];
// make the scrollview our main view
[self setView:scrollView];
// now create the GLKView and context
EAGLContext * context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
glkView = [[GLKView alloc] initWithFrame:screenRect];
glkView.context = context;
glkView.delegate = self;
// add the GLKView to the scrollView
[scrollView addSubview:glkView];
/* old code, which works fine */
// OpenGLView openGLView = [[OpenGLView alloc] initWithFrame: screenRect];
// openGLView.delegate = self;
// openGLView.opaque = NO;
// [scrollView addSubview:openGLView];
/* end of old code */
// and finally tell the scrollview the size of it's content
[scrollView setContentSize:screenRect.size];
}
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
// ** THROWS THE ERROR BEFORE HERE ** //
// set the background colour to red
glClearColor(1.0, 0.0, 0.0, 1.0);
// and now clear it
glClear(GL_COLOR_BUFFER_BIT);
}
Any reason why this code would be causing this to happen?
This error occurs for me when instantiating views off of the main thread.
FWIW, the 8cd6 in the error message is the OpenGL error code for GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT, which means something about the OpenGL frame buffer was not completely configured.