ios - OpenGL ES 2.0无效的可绘制错误

标签 ios objective-c graphics opengl-es opengl-es-2.0

我正在尝试为正在构建的iOS应用程序设置openGL,但出现以下错误:

-[EAGLContext renderbufferStorage:fromDrawable:]: invalid drawable

这是我的代码的一部分,位于UIViewController类中:
@implementation MyViewController
{
    CAEAGLayer *_eaglLayer;
    EAGLContext *_context;
    GLuint _colorRenderBuffer;
}


+(Class)layerClass
{
    return [CAEAGLLayer class];
}

-(void)setup
{
    _eaglLayer = (CAEAGLLayer *)self.view.layer;
    _eaglLayer.opaque = YES;  

    EAGLRenderingAPI api = kEAGLRenderingAPIOpenGLES2;
    _context = [[EAGLContext alloc] initWithAPI:api];

    glGenRenderbuffers(1, &_colorRenderBuffer);
    glBindRenderbuffer(GL_RENDERBUFFER, _colorRenderBuffer);
    [_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:_eaglLayer];
}

如何解决此错误?

最佳答案

创建上下文后,尝试使其成为当前上下文。我相信,尽管其中一些辅助类为您带来了所有“魔力”,但这不会自动发生。

_context = [[EAGLContext alloc] initWithAPI:api];
[EAGLContext setCurrentContext: _context];

第一行是您已经拥有的内容,第二行是您添加的内容。

关于ios - OpenGL ES 2.0无效的可绘制错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23551370/

相关文章:

ios - WatchKit 如何处理同一张 map 上的多个 map 标注?

ios - 创建和使用可在 Apple Watch 扩展中使用的框架是否需要特殊步骤?

html - RoR 中的图像叠加

java - 可执行 jar 中的图形停止

java打印 - 边框的设置大小

ios - 如何将数据从一个容器传递到另一个容器,两者都嵌入在 swift 中的同一个 uiviewcontroller 中?

objective-c - 无法在 Xcode 4 上编译 Objective-C

ios - 修改数据模型后xcode更新类

ios - 深入了解保留周期

objective-c - 按下搜索栏 'Search"按钮时如何关闭键盘?