title: Directx: Obj file parsing to Index Buffer
body: <p>I'm having trouble getting an index buffer to display some imported .obj correctly.
  It's been taken into consideration coordinate system orientation. (The obj loader was hard coded)  can print out the indices fine, so it correctly fills a <code>DWORD</code> array to be read in and set:</p>
  
  <pre><code>vector &lt; vector &lt;float&gt; &gt; index;
  index = GetObjData(FilePath, VERTEXINDEXLIST);
  for (int n=0; n&lt;index.size(); n++){
      m=m+index[n].size();
  }
  </code></pre>
  
  <p>...</p>
  
  <pre><code>DWORD *IndexBuffer = new DWORD[m];
  </code></pre>
  
  <p>...</p>
  
  <pre><code>iBufferDescription.Usage                   =D3D11_USAGE_DEFAULT;
  iBufferDescription.ByteWidth               =sizeof(DWORD)*m;
  iBufferDescription.BindFlags               =D3D11_BIND_INDEX_BUFFER;
  iBufferDescription.CPUAccessFlags          =0;
  iBufferDescription.MiscFlags               =0;
  
  D3D11_SUBRESOURCE_DATA iSRData;
  iSRData.pSysMem=IndexBuffer;
  
  Device-&gt;CreateBuffer(&amp;iBufferDescription, &amp;iSRData, &amp;D3DIndexBuffer);
  DeviceContext-&gt;IASetIndexBuffer(D3DIndexBuffer, DXGI_FORMAT_R16_UINT, 0);
  </code></pre>
  
  <p>Here's a Maya generated .obj:</p>
  
  <pre><code># This file uses centimeters as units for non-parametric coordinates.
  
  mtllib tbox.mtl
  g default
  v -0.500000 -0.500000 -0.000000
  v 0.500000 -0.500000 -0.000000
  v -0.500000 0.500000 0.000000
  v 0.500000 0.500000 0.000000
  vt 0.000000 0.000000
  vt 1.000000 0.000000
  vt 0.000000 1.000000
  vt 1.000000 1.000000
  vn 0.000000 -0.000000 1.000000
  vn 0.000000 -0.000000 1.000000
  vn 0.000000 -0.000000 1.000000
  vn 0.000000 -0.000000 1.000000
  s 1
  g pPlane1
  usemtl initialShadingGroup
  f 1/1/1 2/2/2 3/3/3
  f 3/3/3 2/2/2 4/4/4
  </code></pre>
  
  <p>A 2D square with 4 vertices.Passed in through the function, <code>DWORD IndexBuffer</code>'s contents read:</p>
  
  <pre><code>2
  1
  0
  3
  1
  2
  </code></pre>
  
  <p>(-1 from all indices, to conform to DirectX)
  I will also add that some other things were set too, such as the <code>ID3D11RasterizerState</code>.</p>
  
  <pre><code>D3D11_RASTERIZER_DESC DrawStyleState;
  DrawStyleState.AntialiasedLineEnable=true;
  DrawStyleState.CullMode=D3D11_CULL_NONE;
  DrawStyleState.DepthBias=0;
  DrawStyleState.FillMode=D3D11_FILL_SOLID;
  DrawStyleState.DepthClipEnable=true;
  DrawStyleState.MultisampleEnable=true;
  DrawStyleState.FrontCounterClockwise=false;
  DrawStyleState.ScissorEnable=false;
  
  ID3D11RasterizerState *DS_State;
  Device-&gt;CreateRasterizerState(&amp;DrawStyleState, &amp;DS_State);
  DeviceContext-&gt;RSSetState(DS_State);
  </code></pre>
  
  <p>Finally the render function is pretty standard:</p>
  
  <pre><code>void Render(){
  float ColorBlue[] = {0.3f,0.3f,1.0f,1.0f};
  DeviceContext-&gt;ClearRenderTargetView(RenderTargetView,ColorBlue);
      UINT stride=sizeof(VERTEX);
      UINT Offset=0;
      DeviceContext-&gt;IASetVertexBuffers(0,1,&amp;D3DBuffer,&amp;stride,&amp;Offset);
      DeviceContext-&gt;IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);    
      DeviceContext-&gt;DrawIndexed(IndSz,0,0);
  Swapchain-&gt;Present(0,0);
  
  }
  </code></pre>
  
  <p>IndSz is a global, for the index size. Which is correct:
  I created a debugger for it, giving feedback:</p>
  
  <pre><code>4 vertices
  6 index array size //element size = IndSz 
  Index 0: 2
  Index 1: 1
  Index 2: 0
  Index 3: 3
  Index 4: 1
  Index 5: 2
  </code></pre>
  
  <p>The above gets parsed into 1 triangle.</p>
  
  <pre><code>|\
  | \
  |  \ 
  |   \
  ------
  </code></pre>
  
  <p>I've concluded it might be another issue other than what I can conceive of. I've checked for culling issues, ordering, data type funniness, memory size craziness and it seems close to a rewrite now. Help!</p>