android - GLES 错误 : vertex attribute array is enabled with no data bound

标签 android c++ opengl-es android-ndk opengl-es-2.0

OpenGl 的新手,目前正在研究 Android NDK。我目前收到此错误,无法弄清楚。我觉得这是基本的东西,但我可能是错的。 appRender 由 java 渲染端在每一帧运行。

错误:

E/emuglGLESv2_enc: glDrawArrays: a vertex attribute array is enabled with no data bound

应用程序.cpp:

void appRender(long tick, int width, int height){
    const float vertices[] =
    {
         0.0f,  0.5f, 0.0f,
        -0.5f, -0.5f, 0.0f,
         0.5f, -0.5f, 0.0f
    };

    glClear(GL_COLOR_BUFFER_BIT);

    GLuint vertexBuffer;
    glGenBuffers(1, &vertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

    // Setup colors for each vertex
    GLfloat colors[3*4];
    for (int v = 0; v < 3; v++){
        colors[4*v+0] = 0;
        colors[4*v+1] = 1;
        colors[4*v+2] = 0;
        colors[4*v+3] = 1;
    }

    // Setup color buffer
    GLuint colorBuffer;
    glGenBuffers(1, &colorBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, colorBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_STATIC_DRAW);

    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
    glVertexAttribPointer(
        1,
        3,
        GL_FLOAT,
        GL_FALSE,
        0,
        (void*)0
        );

    glEnableVertexAttribArray(1);
    glBindBuffer(GL_ARRAY_BUFFER, colorBuffer);
    glVertexAttribPointer(
        1,
        4,
        GL_FLOAT,
        GL_FALSE,
        0,
        (void*)0
        );


    glDrawArrays(GL_TRIANGLES, 0, 3);
    glDisableVertexAttribArray(0);
    glDisableVertexAttribArray(1);

    glBindTexture(GL_TEXTURE_2D, 0);
    //textRenderer.RenderTexts(0.5f);
    //boxRenderer.RenderBoxes(0.5f);
}

最佳答案

所以我找到了,是的,我很糟糕。

glVertexAttribPointer(1,3,...) -> glVertexAttribPointer(0,3,...)

关于android - GLES 错误 : vertex attribute array is enabled with no data bound,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38061605/

相关文章:

ios - 禁用 opengl es 纹理 ios

java - 谷歌地图 API 出现 DexIndexOverflowException

android - 通过指定的 SIM 从 android 调用

c - 向函数发送指针数组

c++ - C++11 中的生产者-消费者

c++ - Winapi ListView_GetItemText 错误的输出格式

android - 使用 OpenGL ES 2.0 在 Android 中进行双缓冲区页面翻转

android - Jetpack-Android 仅当对象的某个属性发生变化时如何触发重组

list 中的 Android 元数据返回 null

c++ - 如何从自动返回类型推导出类型?