title: How to use glVertexAttrib
body: <p>For my shader, I don't want to enable all attributes for all draw calls. For example in one draw call, I want to use different color for each vertex which is stored in vertex buffer. So I use <code>glEnableVertexAttribArray</code> and <code>glVertexAttribPointer</code> to bind the buffer and it works fine.</p>
  
  <p>However I can't use <code>glVertexAttrib</code> methods for constant colors. Did I misunderstood of these methods? <a href="https://stackoverflow.com/questions/9402457/can-you-tell-if-a-vertex-attribute-is-enabled-from-within-a-vertex-shader">Can you tell if a vertex attribute is enabled from within a vertex shader?</a> says that </p>
  
  <blockquote>
    <p>If an attribute is disabled, its value comes from regular OpenGL state. Namely, the state set by the glVertexAttrib functions</p>
  </blockquote>
  
  <p>But when I disable <code>glDisableVertexAttribArray</code> and use <code>glVertexAttrib</code> to set it to a constant, it does not render anything. If I try to use that attribute in the shader, it simply renders black.</p>
  
  <p>What am I missing?</p>
  
  <p>edit:</p>
  
  <p>My code is something like this (it has some abstraction but call order for gl functions is this)</p>
  
  <pre><code>    glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
      glEnableVertexAttribArray(position);
      glVertexAttribPointer(position, 3, GL_FLOAT, false, sizeof(Vertex), 0);
      glEnableVertexAttribArray(normal);
      glVertexAttribPointer(normal, 3, GL_FLOAT, true, sizeof(Vertex), (void*)(sizeof(Vec3)));
      glEnableVertexAttribArray(color);
      glVertexAttribPointer(color, 4, GL_FLOAT, false, sizeof(Vertex), (void*)(sizeof(Vec3)+sizeof(Vec3)));
  
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
  
      glDrawElements(
          GL_TRIANGLES,
          (edgeCount - 1)*(edgeCount - 1) * 6,
          GL_UNSIGNED_INT,
          (void*)0
          );
  </code></pre>
  
  <p>This works however when I replace <code>
          glEnableVertexAttribArray(color);
          glVertexAttribPointer(color, 4, GL_FLOAT, false, sizeof(Vertex), (void*)(sizeof(Vec3)+sizeof(Vec3)));</code></p>
  
  <p>with </p>
  
  <pre><code>glDisableVertexAttribArray(color);
  glVertexAttrib4f(color, 1.0f, 0.0, 0.0, 1.0);
  </code></pre>
  
  <p>It does not work.</p>