title: VAOs and Element Buffer Objects
body: <p>I've been reading a bit about how VAOs work with VBOs. As far as I understand, the VAO only stores state information about a VBO when we call glVertexAttribPointer. My question is, when does it store state about an EBO (for indexed drawing), does it save state for both when glVertexAttribPointer is called?</p>
  
  <pre><code>//Vertices of the rectangle
  std::vector&lt;GLfloat&gt; vertices
  {
      0.5f,  0.5f, 0.0f,  // Top Right
      0.5f, -0.5f, 0.0f,  // Bottom Right
      -0.5f,  0.5f, 0.0f,  // Top Left 
      -0.5f, -0.5f, 0.0f,  // Bottom Left
  };
  
  //Indices of the triangle
  std::vector&lt;GLuint&gt; indices
  {
      0, 1, 3,
      0, 3, 2
  };
  
  
  GLuint VAO, VBO, EBO; 
  glGenVertexArrays(1, &amp;VAO);
  glGenBuffers(1, &amp;VBO);
  glGenBuffers(1, &amp;EBO);
  
  glBindVertexArray(VAO); //Bind the VAO
  
  //Bind the buffers
  glBindBuffer(GL_ARRAY_BUFFER, VBO);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
  
  glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(GLfloat), &amp;vertices[0], GL_STATIC_DRAW);
  
  glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
  glEnableVertexAttribArray(0);
  
  glBindVertexArray(0); //Unbind the VAO
  
  //Supply Index Buffer information
  glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GLuint), &amp;indices[0], GL_STATIC_DRAW);
  
  glBindBuffer(GL_ARRAY_BUFFER, 0);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  
  //Custom shader class that stores the program to be used at render time
  Shader shader("..path_to_shader\\shaders\\vertexshader.vert", "..path_to_shader\\shaders\\fragmentshader.frag");
  
  while (!glfwWindowShouldClose(window))
  {
      glUseProgram(shader.Program());
      glBindVertexArray(VAO); //Bind the VAO to draw.
      glClearBufferfv(GL_COLOR, 0, &amp;color[0]);
  
      glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr);
  
      glfwPollEvents();
      glfwSwapBuffers(window);
  
      glBindVertexArray(0);
      glUseProgram(0);
  }
  </code></pre>