我正在尝试用 OpenGL ES 2.0 GLKit 画一条线。当我运行以下代码并使用 OpenGL ES Analyzer 时,我收到以下错误:
“使用不存在的程序”glDrawArrays(GL_LINE_STRIP,0,4)
“GL 错误:无效操作” GL_INVALID_OPERATION <- glVertexPointer(2,GL_FLOAT,0,NULL) GL_INVALID_OPERATION <- glEnableClientState(GL_VERTEX_ARRAY)
这是我的代码:
#import "GLDrawingView.h"
const float data[] = {0.0f, 1.0f, 0.0f, 0.0f, 1.0f, -0.0f, 0.0f, 1.0f};
@interface GLDrawingView () {
GLuint lineVBO;
}
@end
@implementation GLDrawingView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[EAGLContext setCurrentContext:self.context];
glGenBuffers(1, &lineVBO);
glBindBuffer(GL_ARRAY_BUFFER, lineVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
}
return self;
}
- (void)drawRect:(CGRect)rect
{
glVertexPointer(2, GL_FLOAT, 0, NULL);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_LINE_STRIP, 0, sizeof(data) / sizeof(float) / 2);
}
@end