没有使用VBO着色线

时间:2014-05-08 11:18:54

标签: ios opengl-es-2.0 glkit

我正在尝试并且未能使用glkit / OpenGL Es2绘制颜色线。我可以画线,但它是黑色的。

我目前的方法是尝试使用包含位置和颜色数据的VBO。

设置:

typedef struct {
    float Position[2];
    float Color[4];
} LinePoint;

LinePoint line[] =
{
    {{0.0, 0.0},{1.0,0.0,0.0,1}},
    {{2.0, 3.0},{1.0,0.0,0.0,1}}
};

glGenBuffers(1, &_lineBuffer);
glBindBuffer(GL_ARRAY_BUFFER, _lineBuffer);
glBufferData(GL_ARRAY_BUFFER,sizeof(LinePoint)*2,line,GL_STATIC_DRAW);

在我的drawInRect方法中:

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect {

    [EAGLContext setCurrentContext:self.context];

    [self.effect prepareToDraw];

    glClearColor(0.5, 0.5, 0.5, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);

    glDisable(GL_BLEND);
    glDisable(GL_TEXTURE_2D);

    glBindBuffer(GL_ARRAY_BUFFER, _lineBuffer);
    glEnableVertexAttribArray(GLKVertexAttribPosition);
    glVertexAttribPointer(GLKVertexAttribPosition,2,GL_FLOAT,GL_FALSE,sizeof(LinePoint),(const GLvoid *) offsetof(LinePoint, Position));

    glEnableVertexAttribArray(GLKVertexAttribColor);
    glVertexAttribPointer(GLKVertexAttribColor,4,GL_FLOAT,GL_FALSE,sizeof(LinePoint),(const GLvoid *) offsetof(LinePoint, Color));



    // Set the line width
    glLineWidth(50.0);

    // Render the line

    glDrawArrays(GL_LINE_STRIP, 0, 2);

    glEnable(GL_BLEND);
    glEnable(GL_TEXTURE_2D);

    }

0 个答案:

没有答案