openglvao

How to use glVertexAttrib3f with vao?


I use vao and vbo to draw a quad. A vertex shader has the following input:

layout (location = 0) in vec3 pos

I would like to use glVertexAttrib3f to set a constant pos value for the vertex shader. The following code has no effect (the quad is drawing):

glVertexAttrib3f(0, 0.0f, 0.0f, 0.0f);
glUseProgram(shaderProgram);
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);

What is wrong ?


Solution

  • See OpenGL 4.6 API Core Profile Specification - 10.2 Current Vertex Attribute Values:

    The commands in this section are used to specify current attribute values. These values are used by drawing commands to define the attributes transferred for a vertex when a vertex array defining a required attribute is not enabled [...]

    Note, the current Vertex attribute values are not stated in the vertex array object.

    The vertex attribute with the specified index has to be disabled:

    glBindVertexArray(VAO);
    glDisableVertexAttribArray(0);