title: In What Order Should I Send My Vertices To OpenGL for Culling
body: <p>I'm learning a spot of 3d opengl, and it's going rather well, I've got a nice camera moving about and some simple cube objects, at the moment. Currently using vertex arrays, but I'm swapping to VBOs pretty quick here. I'm just trying to enable culling, however I'm not sure what order in which I ought to specify my vertices, right now this is what I'm doing: </p>
  
  <pre><code>void cube::update_verts(){
  GLushort cur=0;
  
  ///back face
  verts[cur++]=x; verts[cur++]=y; verts[cur++]=z;
  verts[cur++]=x+sx; verts[cur++]=y; verts[cur++]=z;
  verts[cur++]=x+sx; verts[cur++]=y+sy; verts[cur++]=z;
  verts[cur++]=x; verts[cur++]=y+sy; verts[cur++]=z;
  
  ///right face
  verts[cur++]=x+sx; verts[cur++]=y+sy; verts[cur++]=z;
  verts[cur++]=x+sx; verts[cur++]=y; verts[cur++]=z;
  verts[cur++]=x+sx; verts[cur++]=y; verts[cur++]=z+sz;
  verts[cur++]=x+sx; verts[cur++]=y+sy; verts[cur++]=z+sz;
  
  ///top face
  verts[cur++]=x+sx; verts[cur++]=y+sy; verts[cur++]=z;
  verts[cur++]=x; verts[cur++]=y+sy; verts[cur++]=z;
  verts[cur++]=x; verts[cur++]=y+sy; verts[cur++]=z+sz;
  verts[cur++]=x+sx; verts[cur++]=y+sy; verts[cur++]=z+sz;
  
  ///front face
  verts[cur++]=x; verts[cur++]=y; verts[cur++]=z+sz;
  verts[cur++]=x+sx; verts[cur++]=y; verts[cur++]=z+sz;
  verts[cur++]=x+sx; verts[cur++]=y+sy; verts[cur++]=z+sz;
  verts[cur++]=x; verts[cur++]=y+sy; verts[cur++]=z+sz;
  
  ///bottom face
  verts[cur++]=x+sx; verts[cur++]=y; verts[cur++]=z;
  verts[cur++]=x; verts[cur++]=y; verts[cur++]=z;
  verts[cur++]=x; verts[cur++]=y; verts[cur++]=z+sz;
  verts[cur++]=x+sx; verts[cur++]=y; verts[cur++]=z+sz;
  
  ///left face
  verts[cur++]=x; verts[cur++]=y+sy; verts[cur++]=z;
  verts[cur++]=x; verts[cur++]=y; verts[cur++]=z;
  verts[cur++]=x; verts[cur++]=y; verts[cur++]=z+sz;
  verts[cur++]=x; verts[cur++]=y+sy; verts[cur++]=z+sz;
  
  
  }
  
  ///Drawing Code:
  
  glVertexPointer(3,GL_FLOAT,0,object.verts);
  glColorPointer(3,GL_UNSIGNED_BYTE,0,object.colors);
  glDrawArrays(GL_QUADS,0,6*4);
  </code></pre>
  
  <p>However it's definitely quite wrong, because when I <code>glEnable(GL_CULL_FACE);</code> my cubes don't show the correct faces (as seen below).</p>
  
  <p><strong>Normal</strong>
  <img src="https://i.stack.imgur.com/I5pZJ.png" alt="Regular View From Top"></p>
  
  <p><strong>Problem Child</strong>
  <img src="https://i.stack.imgur.com/NMWVU.png" alt="View From Side"></p>
  
  <p>With both of these images culling is enabled.</p>
  
  <p>In what order should I specify the vertices?</p>
  
  <hr>
  
  <p>(EDIT) <strong>Updated Working Function:</strong></p>
  
  <pre><code>void cube::update_verts(){
  GLushort cur=0;
  
  ///top face
  verts[cur++]=x; verts[cur++]=y+sy; verts[cur++]=z;
  verts[cur++]=x; verts[cur++]=y+sy; verts[cur++]=z+sz;
  verts[cur++]=x+sx; verts[cur++]=y+sy; verts[cur++]=z+sz;
  verts[cur++]=x+sx; verts[cur++]=y+sy; verts[cur++]=z;
  
  
  ///bottom face
  verts[cur++]=x; verts[cur++]=y; verts[cur++]=z;
  verts[cur++]=x+sx; verts[cur++]=y; verts[cur++]=z;
  verts[cur++]=x+sx; verts[cur++]=y; verts[cur++]=z+sz;
  verts[cur++]=x; verts[cur++]=y; verts[cur++]=z+sz;
  
  ///left face
  verts[cur++]=x; verts[cur++]=y; verts[cur++]=z;
  verts[cur++]=x; verts[cur++]=y; verts[cur++]=z+sz;
  verts[cur++]=x; verts[cur++]=y+sy; verts[cur++]=z+sz;
  verts[cur++]=x; verts[cur++]=y+sy; verts[cur++]=z;
  
  ///right face
  verts[cur++]=x+sx; verts[cur++]=y; verts[cur++]=z;
  verts[cur++]=x+sx; verts[cur++]=y+sy; verts[cur++]=z;
  verts[cur++]=x+sx; verts[cur++]=y+sy; verts[cur++]=z+sz;
  verts[cur++]=x+sx; verts[cur++]=y; verts[cur++]=z+sz;
  
  ///front face
  verts[cur++]=x; verts[cur++]=y; verts[cur++]=z+sz;
  verts[cur++]=x+sx; verts[cur++]=y; verts[cur++]=z+sz;
  verts[cur++]=x+sx; verts[cur++]=y+sy; verts[cur++]=z+sz;
  verts[cur++]=x; verts[cur++]=y+sy; verts[cur++]=z+sz;
  
  
  ///back face
  verts[cur++]=x; verts[cur++]=y; verts[cur++]=z;
  verts[cur++]=x; verts[cur++]=y+sy; verts[cur++]=z;
  verts[cur++]=x+sx; verts[cur++]=y+sy; verts[cur++]=z;
  verts[cur++]=x+sx; verts[cur++]=y; verts[cur++]=z;
  
  }
  </code></pre>