title: Direct3D C++ texture mapping
body: <p>Hey guys can anybody help me with texture mapping in Direct3D C++. I have created a basic game and want to texture the enviroment. I have looked at numerous online tutorials but have had no luck so far</p>
  
  <p>I am creating a custom vertex for my drawing code:</p>
  
  <pre><code>struct CUSTOMVERTEX
  {
      FLOAT x, y, z; // The position for the vertex
      DWORD color;        // The vertex color
  };
  </code></pre>
  
  <p>This is how I would draw a square:</p>
  
  <pre><code>CUSTOMVERTEX g_Vertices[] =
  {
  
     {-1.0f,-1.0f,-1.0f,0xFF0000FF},{-1.0f, 1.0f,-1.0f,0xFF0000FF},
     { 1.0f, 1.0f,-1.0f,0xFF0000FF}, { 1.0f, 1.0f,-1.0f,0xFF0000FF},
     { 1.0f,-1.0f,-1.0f,0xFF0000FF},{-1.0f,-1.0f,-1.0f,0xFF0000FF},
  
  };
  </code></pre>
  
  <p>Here is the buffer:</p>
  
  <pre><code>//*************************** Vertex Buffer ****************************
  if( FAILED( g_pd3dDevice-&gt;CreateVertexBuffer( numberOfVertecies*sizeof(CUSTOMVERTEX), 
          0 /* Usage */, D3DFVF_CUSTOMVERTEX,D3DPOOL_MANAGED, &amp;g_pVB, NULL ) ) )
      MessageBox(hwnd,"Vertex Buffer problem",NULL,NULL);
  
  VOID* pVertices;
  
  if( FAILED( g_pVB-&gt;Lock( 0, sizeof(g_Vertices), (void**)&amp;pVertices, 0 ) ) )
      MessageBox(hwnd,"Vertex Lock Problem",NULL,NULL);
  
  memcpy( pVertices, g_Vertices, sizeof(g_Vertices) );
  
  g_pVB-&gt;Unlock();
  </code></pre>
  
  <p>and here is the square:</p>
  
  <pre><code>g_pd3dDevice-&gt;SetTransform( D3DTS_WORLD, &amp;g_matWorld );
  g_pd3dDevice-&gt;SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
  g_pd3dDevice-&gt;SetFVF( D3DFVF_CUSTOMVERTEX );
  g_pd3dDevice-&gt;DrawPrimitive( D3DPT_TRIANGLELIST, 0, 20);
  </code></pre>
  
  <p>I just want to see how to texture the square so I can go on to texturing my whole enviroment?</p>