title: Opengl - indexList for OBJ-file with textures for VBO (glDrawElements)
body: <p>i've made an obj-loader for opengl. Therefore i read all faces (one by one) and write the ordered vertices, normals and uv-coords in (openGL-)buffers (GL_ARRAY_BUFFER). That means i dulicate all necessary vertices, normals and uv-coords depending on what the faces-section in the obj-file says. Then i draw them with glDrawArrays()</p>
  <p>... all fine.</p>
  <p>To save some memory, i thought to use an index list, and use glDrawElements(), but i got one problem. See the two following Pictures:</p>
  <p><a href="https://i.stack.imgur.com/45fmE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/45fmE.png" alt="a triangulated Quad" /></a></p>
  
  <p><a href="https://i.stack.imgur.com/ExQ24.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ExQ24.png" alt="a UV-Map" /></a></p>
  
  <p>Consider vertex P0 and the triangles and what it would be in the face-section of an OBJ-file</p>
  <p>Triangle</p>
  <pre><code>T1 --&gt; f   vertex(0)/P0/normal(0)   vertex(1)/P1/normal(1)   vertex(2)/P2/normal(2)
  
  T2 --&gt; f   vertex(0)/P0/normal(0)   vertex(1)/P1/normal(1)   vertex(5)/P5/normal(5)
  
  T3 --&gt; f   vertex(0)/P0/normal(0)   vertex(2)/P2/normal(2)   vertex(3)/P3/normal(3)
  </code></pre>
  <p>... all fine, but</p>
  <pre><code>T4 --&gt; f   vertex(0)/P'0/normal(0)   vertex(3)/P3/normal(3)   vertex(4)/P4/normal(4)
  
  T5 --&gt; f   vertex(0)/P'0/normal(0)   vertex(4)/P4/normal(4)   vertex(5)/P5/normal(5)
  </code></pre>
  <p>ok whats the Problem?</p>
  <pre><code>vertex(0)/P0/normal(0) != vertex(0)/P'0/normal(0)
  </code></pre>
  <p>The solution i thought, is something like:</p>
  <ul>
  <li>a list for each vertices, normals, uvs</li>
  <li>read the faces-section of OBJ file
  <ul>
  <li>get the index of the vertex -&gt; write the vertex on position(index) in the vertex-List</li>
  <li>write the normal on position(index) in the normal-List</li>
  <li>write the uv on position(index) in the uv-List</li>
  <li>now the problem vertex with different uv-coord, therefore
  <ul>
  <li>check the list-element if not &quot;empty&quot; or not 0 --&gt; ok there is a vertex and we must duplicate the current vertex, normal, and UV and write them on a new index in all the list, and write the new index to the index list</li>
  </ul>
  </li>
  </ul>
  </li>
  </ul>
  <p>now my Question...</p>
  <p>is there a better way to handle the problem with the different uv-coords for the same vertex in the face-section of the obj file?</p>