title: Understanding code used to draw quads in OpenGL 3.3+ core using triangles
body: <p>I'm trying to draw a quad for a background (2D) using OpenGL 3.x+.  Quads are deprecated, so the goal is to use two triangles to make a rectangle that fills the screen.  It's working, but I'm not 100% clear on everything here.  </p>
  
  <ol>
  <li><p>Setup</p>
  
  <pre><code>GLuint positionBufferObject;
  GLfloat vertexPositions[] =
  {
      -1.0f, -1.0f, 0.0f, 1.0f,
      -1.0f,  1.0f, 0.0f, 1.0f,
       1.0f,  1.0f, 0.0f, 1.0f,
       1.0f, -1.0f, 0.0f, 1.0f,
      -1.0f, -1.0f, 0.0f, 1.0f,
  };
  glGenBuffers(1, &amp;positionBufferObject);
  glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
  glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW);
  </code></pre>
  
  <ul>
  <li>I understand the <code>vertexPositions</code>, it's an array of vertices.</li>
  <li><code>glGenBuffers()</code> is saying, I want 1 buffer and assign id to <code>&amp;positionBufferObject</code>?</li>
  <li><code>glBufferData()</code> uploads the <code>vertexPositions</code> to the GPU's memory; but how does it know were to upload it since I didn't give it an ID?  </li>
  </ul></li>
  <li><p>Draw</p>
  
  <pre><code>glEnableVertexAttribArray(0);
  glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
  glDrawArrays(GL_TRIANGLE_STRIP, 0, 5);
  glDisableVertexAttribArray(0);
  </code></pre>
  
  <ul>
  <li><code>glEnableVertexAttribArray()</code> just says I'm going to be drawing with array 0?</li>
  <li><code>glDrawArrays()</code> - what if I want to draw two vertex arrays?  How does it know which ones to render?  It knows that from the above command?</li>
  <li>Not sure what <code>glVertexAttribPointer()</code> does?</li>
  <li><code>glDrawArrays()</code> is clear.</li>
  </ul></li>
  <li><p>Clean up, I think this is right?</p>
  
  <pre><code>glBindBuffer(GL_ARRAY_BUFFER, 0);
  glDeleteBuffers(1, &amp;positionBufferObject);
  </code></pre>
  
  <p>I only do the setup/cleanup once. </p></li>
  </ol>
  
  <p>Bonus points:</p>
  
  <ul>
  <li>Is this the most effective way to render this?  I read that I'm suppose to be submitting and be rendering in "batches" [?] since 3.x+ doesn't do immediate mode any more.   There is also only one array, so batches won't help performance in this case, but if I had say "a very large number" of vertxArrays to draw, would it be the same process?</li>
  <li>In setup they are storing the array id as positionBufferObject, but have it hardcoded in the rendering loop. Seems like it would get confusing after a dozen or so arrays, why isn't it good practice to use the variable instead of hardcode it?</li>
  </ul>