1

I am trying to draw a line with OpenGL ES 2.0 GLKit. When I run the following code and use OpenGL ES Analyzer I get the following errors:

"Use of Non-Existent Program" glDrawArrays(GL_LINE_STRIP,0,4)

"GL Error: Invalid Operation" GL_INVALID_OPERATION <- glVertexPointer(2,GL_FLOAT,0,NULL) GL_INVALID_OPERATION <- glEnableClientState(GL_VERTEX_ARRAY)

Here's my code:

#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
Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
prplehaze
  • 459
  • 4
  • 15

1 Answers1

5

When you draw something in OpenGL ES 2.0 you must use shader program (glUseProgram) for rendering. You can not render without shaders in GLES2.

Mārtiņš Možeiko
  • 12,733
  • 2
  • 45
  • 45
  • Are you certain about this? I have a GLKit app that does not use shaders -- or, if it does, they're built-in; I certainly didn't code or compile any! -- and it renders just fine. – Olie May 27 '13 at 02:54
  • glkit has built in shaders that mimic ES 1.0 functionality, thats basically what that effect class is. glkit is a wrapper for opengl es 2.0 – Fonix May 28 '13 at 09:39