我正在尝试将GLKView添加到滚动视图但没有成功。
目前,我的绘图代码只是将背景颜色设置为红色,但在它实现之前,它会抛出错误“Failed to make framebuffer object 8cd6”错误。我已经设法通过将OpenGL绘制到标准的UIView中来完成同样的工作,但是只要将其切换为GLKView,它就会抛出错误。
以下是我在AppDelegate.m中初始化滚动视图的方式:
ScrollView *scroll = [[ScrollView alloc] init];
[[self window] setRootViewController:scroll];
然后在我的ScrollView.m本身中有以下内容:
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);
}
这段代码导致这种情况发生的原因是什么?
答案 0 :(得分:2)
当从主线程实例化视图时,我会发生此错误。
FWIW,错误消息中的8cd6是GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT的OpenGL错误代码,这意味着OpenGL帧缓冲区没有完全配置。