title: How to create Cubemap in DirectX 9
body: <p>I'm trying to create a Cube Map in DirectX 9, but for some reason it's not working. I've used DirectX's Texture Utility to create a dds texture file for the cube, but when I draw it, it's only drawing a solid color. Here's the code I've done:</p>
  
  <p><strong>SkyBox.h</strong></p>
  
  <pre><code>#pragma once
  
  #include&lt;D3DX9Mesh.h&gt;
  #include"DirectX.h"
  
  class SkyBox{
  public:
      SkyBox(LPCSTR textureFile);
      ~SkyBox();
  
      void Draw();
  
  protected:
      IDirect3DCubeTexture9* texture;
      LPD3DXMESH mesh;
  };
  </code></pre>
  
  <p><strong>SkyBox.cpp</strong></p>
  
  <pre><code>#include"SkyBox.h"
  
  SkyBox::SkyBox(LPCSTR textureFile)
  {
      D3DXCreateBox(DirectX::device, 1.0f, 1.0f, 1.0f, &amp;mesh, NULL);
      D3DXCreateCubeTextureFromFile(DirectX::device, textureFile, &amp;texture);
  }
  
  SkyBox::~SkyBox()
  {
      mesh-&gt;Release();
      texture-&gt;Release();
  }
  
  void SkyBox::Draw()
  {
      D3DXHANDLE textureHandle = DirectX::currentShaderEffect-&gt;GetParameterByName(0, "tex0");
      DirectX::currentShaderEffect-&gt;SetTexture(textureHandle, texture);
      DirectX::currentShaderEffect-&gt;CommitChanges();
  
      UINT passNum = 5;
      DirectX::currentShaderEffect-&gt;Begin(&amp;passNum, 0);
      DirectX::currentShaderEffect-&gt;BeginPass(5);
  
      mesh-&gt;DrawSubset(0);
  
      DirectX::currentShaderEffect-&gt;EndPass();
      DirectX::currentShaderEffect-&gt;End();
  }
  </code></pre>
  
  <p>And this is my shader for the Cube Map:</p>
  
  <pre><code>uniform extern float4x4 mvp;
  uniform extern texture tex0;
  
  struct SkyboxVS
  {
  
      float4 pos : POSITION0;
      float3 uv0 : TEXCOORD0;
  };
  
  sampler SkyBoxTex = sampler_state
  {
      Texture = &lt;tex0&gt;;
      MinFilter = LINEAR;
      MagFilter = LINEAR;
      MipFilter = LINEAR;
      AddressU = WRAP;
      AddressV = WRAP;
  };
  
  SkyboxVS VertexSkybox(float3 position : POSITION0, float3 texCoord : TEXCOORD0)
  {
      SkyboxVS skyVS = (SkyboxVS)0;
  
      skyVS.pos = mul(float4(position, 1.0f), mvp);
      skyVS.uv0 = texCoord;
  
      return skyVS;
  }
  
  float4 PixelSkybox(float3 texCoord: TEXCOORD0) : COLOR
  {
      float4 color = texCUBE(SkyBoxTex, texCoord);
  
      return color;
  }
  
  technique TransformTech
  {
      pass P5
      {
          vertexShader = compile vs_2_0 VertexSkybox();
          pixelShader = compile ps_2_0 PixelSkybox();
  
          ZFunc = Always;
          StencilEnable = true;
          StencilFunc = Always;
  
          StencilPass = Replace;
          StencilRef = 0;
      }
  }
  </code></pre>