使用“顶点阵列对象”时不会绘制任何内容

时间:2014-02-19 23:51:33

标签: ios graphics opengl-es opengl-es-2.0

我在iOS应用程序中使用以下代码,导致屏幕空白:

void init()
{
    glGenVertexArraysOES(1, &_vaoId);
    glGenBuffers(1, &_vbId);

    glBindVertexArrayOES(_vaoId);
    glBindBuffer(GL_ARRAY_BUFFER, _vbId);

    glVertexAttribPointer(originalPositionPos, 3, GL_FLOAT, GL_FALSE, sizeof(VertexPositionWithColor), (const GLvoid *) offsetof(VertexPositionWithColor, position));
    glEnableVertexAttribArray(originalPositionPos);

    glVertexAttribPointer(originalColorPos, 4, GL_FLOAT, GL_FALSE, sizeof(VertexPositionWithColor), (const GLvoid *) offsetof(VertexPositionWithColor, color));
    glEnableVertexAttribArray(originalColorPos);

    glBindVertexArrayOES(0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
}

void rebinData()
{
    glBindVertexArrayOES(_vaoId);
    glBindBuffer(GL_ARRAY_BUFFER, _vbId);

    glBufferData(GL_ARRAY_BUFFER, sizeof(VertexPositionWithColor) * _linesVertices.size(), &_linesVertices[0], GL_STATIC_DRAW);

    glBindVertexArrayOES(0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
}

void paint()
{
    glBindVertexArrayOES(_vaoId);
    glDrawElements(GL_LINES, (GLsizei)_linesIndices.size(), GL_UNSIGNED_SHORT, &_linesIndices[0]);
}

如果我将glVertexAttribPointer调用移到paint()并将顶点缓冲区绑定在那里,一切正常。我不明白为什么使用顶点数组对象在这里没有按预期工作?

0 个答案:

没有答案