简体   繁体   中英

OpenGL ES 2.0 GLKit Draw a line

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM