Opengl es 无法在没有VAO的情况下在OpenGL中绘制矩形

Opengl es 无法在没有VAO的情况下在OpenGL中绘制矩形,opengl-es,vbo,vao,Opengl Es,Vbo,Vao,我成功地用VAO画了一个矩形。现在我尝试不使用VAO,因为我想在OpenGLES2.0中使用VAO,而VAO是OpenGLES3.0中唯一支持的。然而,我不能让它工作,我做错了什么?非常感谢您的关注和帮助 我的顶点着色器: attribute vec3 position; attribute vec3 color; attribute vec2 texCoord; varying vec3 ourColor; varying vec2 TexCoord; void main() {

我成功地用VAO画了一个矩形。现在我尝试不使用VAO,因为我想在OpenGLES2.0中使用VAO,而VAO是OpenGLES3.0中唯一支持的。然而,我不能让它工作,我做错了什么?非常感谢您的关注和帮助

我的顶点着色器:

attribute vec3 position;
attribute vec3 color;
attribute vec2 texCoord;


varying vec3 ourColor;
varying vec2 TexCoord;


void main()
{
    gl_Position = vec4(position,1.0f); // Add the xOffset to the x position of the vertex position
    ourColor = color;
    TexCoord= vec2(texCoord.x,1.0f-texCoord.y);
}
我的片段着色器:

varying vec3 ourColor;
varying vec2 TexCoord;



uniform sampler2D ourTexture1;
uniform sampler2D ourTexture2;
uniform float mixValue;

void main()
{
gl_FragColor = texture2D(ourTexture1 , TexCoord);
}
我的顶点属性和索引:

GLfloat recVertices[] = {
        // Positions          // Colors          // Texture Coords
        0.5f,  0.5f, 0.0f,   1.0f, 0.0f, 0.0f,   1.0f, 1.0f,   // Top Right
        0.5f, -0.5f, 0.0f,   0.0f, 1.0f, 0.0f,   1.0f, 0.0f,   // Bottom Right
       -0.5f, -0.5f, 0.0f,   0.0f, 0.0f, 1.0f,   0.0f, 0.0f,   // Bottom Left
       -0.5f,  0.5f, 0.0f,   1.0f, 1.0f, 0.0f,   0.0f, 1.0f    // Top Left 
    };

    GLuint indices[] = {  // Note that we start from 0!
        0, 1, 3, // First Triangle
        1, 2, 3  // Second Triangle
    };
我的VAO代码运行良好:

GLuint VBOs[2], VAO ;
glGenBuffers(2, VBOs);

glGenVertexArrays(1, &VAO);

glBindVertexArray(VAO);

glBindBuffer(GL_ARRAY_BUFFER, VBOs[0]);//0. Copy verticles array for OpenGL to use
glBufferData(GL_ARRAY_BUFFER, sizeof(recVertices), recVertices, GL_STATIC_DRAW);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, VBO[1]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);

// 1. set the vertex attributes pointers
// Position Attribute
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)0);
glEnableVertexAttribArray(0);
// Color Attribute
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
glEnableVertexAttribArray(1);
//Texture Coordinate Attribute
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(6 * sizeof(GLfloat)));
glEnableVertexAttribArray(2);
//Unbind VBO
glBindBuffer(GL_ARRAY_BUFFER, 0);


glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
我的代码没有VAO,只使用VBO是行不通的。它没有画任何东西:

    /*-----------------------------------------------------------------------------------------------------------*/
    GLuint VBOs[2], ; // Initialize an buffer to store all the verticles and transfer them to the GPU
glGenBuffers(2, VBOs);


    glBindBuffer(GL_ARRAY_BUFFER, VBO[0]);//0. Copy verticles array for OpenGL to use
    glBufferData(GL_ARRAY_BUFFER, sizeof(recVertices), recVertices, GL_STATIC_DRAW);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, VBO[1] );
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);


    // 1. set the vertex attributes pointers
    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);
    glEnableVertexAttribArray(2);
    // Position Attribute
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)0);

    // Color Attribute
    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));

    //Texture Coordinate Attribute
    glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(6 * sizeof(GLfloat)));


    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);

glBindAttribLocation
调用位于错误的位置。它们必须在着色器编译之后和链接之前调用。否则,
glBindAttribLocation
没有任何效果。@BDL所以我应该将它们放在链接程序函数中,在
glCompileShader
之后和
glAttachShader
之前,对吗?是的。但这可能不是问题所在,因为他们很可能已经分配了相同的位置。我只是想提一下。因此,
glBindAttribLocation
根本没有引起问题,它们在我的代码中没有正确的用途?它可能不会引起问题,但应该存在。无法保证如何自动指定属性位置,但我知道的所有实现都会按照着色器代码中定义的顺序自动指定属性位置。