本文不用GLKit框架来搭建OpenGL ES在iOS上的开发环境。
需要在项目中自定义一个UIView的子类,下面所有操作均在这个子类中进行。
导入头文件
#import <OpenGLES/ES3/gl.h>
将子类view的layer改变一下:
+ (Class)layerClass{
return [CAEAGLLayer class];
}
添加一些用到的成员变量:
@implementation EAGLView
{
EAGLContext *_eaglContext;
CAEAGLLayer *_eaglLayer;
GLuint _colorBufferRender;
GLuint _frameBuffer;
}
设置context,选用版本3的API,context不能跨线程访问:
//设置context
_eaglContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
[EAGLContext setCurrentContext:_eaglContext];
设置layer:
_eaglLayer = (CAEAGLLayer*)self.layer;
_eaglLayer.frame = self.frame;
_eaglLayer.opaque = YES;
_eaglLayer.drawableProperties = [NSDictionary dictionaryWithOb