title: Rendering wireframe no-colour cube with D3DVERTEXELEMENT9 structure
body: <p>I'm pretty new to this structure and the book I'm learning it from is absurdly unintuitive to me. I triple checked the code but I can't figure out why I can't get an image to pop up. The background is white and the HUD is there but the cube won't show up. It was the same when i tried to make it in colour. </p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;windowsx.h&gt;
  #include &lt;d3d9.h&gt;
  #include &lt;d3dx9.h&gt;
  #include &lt;d3dx9core.h&gt;
  #pragma comment (lib, "d3d9.lib")
  #pragma comment (lib, "d3dx9.lib")
  LPDIRECT3D9 d3d;
  LPDIRECT3DDEVICE9 d3ddev;
  //LPDIRECT3DTEXTURE9 quadTexture;
  LPD3DXFONT m_font;
  D3DCOLOR fontColor;
  LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL;
  LPDIRECT3DINDEXBUFFER9 i_buffer = NULL;
  struct ColorVertex{
      D3DXVECTOR3 pos;
      ColorVertex(FLOAT X, FLOAT Y, FLOAT Z):pos(X, Y, Z){}
      static IDirect3DVertexDeclaration9* Decl;
  };
  IDirect3DVertexDeclaration9* ColorVertex::Decl = 0;
  void initD3D(HWND hWnd);
  void render_frame(void);
  void cleanD3D(void);
  void setVertices(void);
  LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  
  int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int  nCmdShow){
      #define SCREEN_WIDTH GetSystemMetrics(SM_CXSCREEN)
      #define SCREEN_HEIGHT GetSystemMetrics(SM_CYSCREEN)
      HWND hWnd;
      WNDCLASSEX wc;
      ZeroMemory(&amp;wc, sizeof(WNDCLASSEX));
      wc.cbSize = sizeof(WNDCLASSEX);
      wc.style = CS_HREDRAW | CS_VREDRAW;
      wc.lpfnWndProc = WindowProc;
      wc.hInstance = hInstance;
      wc.hCursor = LoadCursor(NULL, IDC_ARROW);
      wc.lpszClassName = L"WindowClass";
      RegisterClassEx(&amp;wc);
      hWnd = CreateWindowEx(NULL,
                            L"WindowClass",
                            L"v2",
                            WS_EX_TOPMOST | WS_POPUP,
                            0, 0,
                            SCREEN_WIDTH, SCREEN_HEIGHT,
                            NULL,
                            NULL,
                            hInstance,
                            NULL);
  
      ShowWindow(hWnd, nCmdShow);
      initD3D(hWnd);
      setVertices();
      D3DXCreateFont( d3ddev, 20, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Arial"), &amp;m_font );
      D3DVERTEXELEMENT9 Elements[] = {
          {0,  0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
          D3DDECL_END()
      };
      d3ddev-&gt;CreateVertexDeclaration(Elements, &amp;ColorVertex::Decl);
      MSG msg;
      while(TRUE){
          while(PeekMessage(&amp;msg, NULL, 0, 0, PM_REMOVE)){
              TranslateMessage(&amp;msg);
              DispatchMessage(&amp;msg);
          }
          if(msg.message == WM_QUIT) break;
          render_frame();
      }
      cleanD3D();
      return msg.wParam;
  }
  
  LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
      switch(message){
          case WM_DESTROY:{
                  PostQuitMessage(0);
                  return 0;
          }break;
      }
      return DefWindowProc (hWnd, message, wParam, lParam);
  }
  
  void initD3D(HWND hWnd){
      d3d = Direct3DCreate9(D3D_SDK_VERSION);
      D3DPRESENT_PARAMETERS d3dpp;
      ZeroMemory(&amp;d3dpp, sizeof(d3dpp));
      d3dpp.Windowed = FALSE;
      d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
      d3dpp.hDeviceWindow = hWnd;
      d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
      d3dpp.BackBufferWidth = SCREEN_WIDTH;
      d3dpp.BackBufferHeight = SCREEN_HEIGHT;
      d3d-&gt;CreateDevice(D3DADAPTER_DEFAULT,
                        D3DDEVTYPE_HAL,
                        hWnd,
                        D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                        &amp;d3dpp,
                        &amp;d3ddev);
      d3ddev-&gt;SetRenderState(D3DRS_ZENABLE, TRUE);
      d3ddev-&gt;SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
      d3ddev-&gt;SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
  }
  
  void setVertices(void){
      d3ddev-&gt;CreateVertexBuffer(8*sizeof(ColorVertex),
                             0,
                             0,
                             D3DPOOL_MANAGED,
                             &amp;v_buffer,
                             NULL);
      ColorVertex* cube = 0;
      v_buffer-&gt;Lock(0, 0, (void**)&amp;cube, 0);
              cube[0] = ColorVertex(-1.0f, -1.0f, -1.0f);
              cube[1] = ColorVertex(-1.0f,  1.0f, -1.0f);
              cube[2] = ColorVertex( 1.0f,  1.0f, -1.0f);
              cube[3] = ColorVertex( 1.0f, -1.0f, -1.0f);
              cube[4] = ColorVertex(-1.0f, -1.0f,  1.0f);
              cube[5] = ColorVertex(-1.0f,  1.0f,  1.0f);
              cube[6] = ColorVertex( 1.0f,  1.0f,  1.0f);
              cube[7] = ColorVertex( 1.0f, -1.0f,  1.0f);
      v_buffer-&gt;Unlock();
      d3ddev-&gt;CreateIndexBuffer(12*3*sizeof(WORD),
                              0,
                              D3DFMT_INDEX16,
                              D3DPOOL_MANAGED,
                              &amp;i_buffer,
                              NULL);
      WORD* k = 0;
      i_buffer-&gt;Lock(0, 0, (void**)&amp;k, 0);
          k[0] = 0; k[1] = 1; k[2] = 2;
          k[3] = 0; k[4] = 2; k[5] = 3;
    // Back face.
          k[6] = 4; k[7]  = 6; k[8] = 5;
          k[9] = 4; k[10] = 7; k[11] = 6;
  
    // Left face.
          k[12] = 4; k[13] = 5; k[14] = 1;
          k[15] = 4; k[16] = 1; k[17] = 0;
  
    // Right face.
          k[18] = 3; k[19] = 2; k[20] = 6;
          k[21] = 3; k[22] = 6; k[23] = 7;
  
    // Top face.
          k[24] = 1; k[25] = 5; k[26] = 6;
          k[27] = 1; k[28] = 6; k[29] = 2;
  
    // Bottom face.
          k[30] = 4; k[31] = 0; k[32] = 3;
          k[33] = 4; k[34] = 3; k[35] = 7;
  
      i_buffer-&gt;Unlock();
  }
  
  void render_frame(void){
      d3ddev-&gt;Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0);
      d3ddev-&gt;BeginScene();
      d3ddev-&gt;SetStreamSource(0, v_buffer, 0, sizeof(ColorVertex));
      d3ddev-&gt;SetIndices(i_buffer);
      D3DXMATRIX matView;
      D3DXMatrixLookAtLH(&amp;matView,
                          &amp;D3DXVECTOR3 (0.0f, 5.0f, -5.0f),// the camera position
                          &amp;D3DXVECTOR3 (0.0f, 0.0f, 0.0f), // the look-at position
                          &amp;D3DXVECTOR3 (0.0f, 1.0f, 0.0f));// the up direction
      d3ddev-&gt;SetTransform(D3DTS_VIEW, &amp;matView);
      D3DXMATRIX matProjection;
      D3DXMatrixPerspectiveFovLH(&amp;matProjection,
                                  D3DXToRadian(90),
                                  (FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT,
                                  1.0f,// the near view-plane
                                  5000.0f);// the far view-plane
      d3ddev-&gt;SetVertexDeclaration(ColorVertex::Decl);
      d3ddev-&gt;DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12);
      fontColor = D3DCOLOR_ARGB(255,0,0,255);   
      RECT rct;
      rct.left=10;
      rct.right=SCREEN_WIDTH-10;
      rct.top=10;
      rct.bottom=rct.top+20;
      //WCHAR lookAtPos [32000];
      //swprintf_s(lookAtPos, 32000, L"X=%f, Z=%f, Y=%f", camDirX, camDirZ, camDirY);
      m_font-&gt;DrawText(NULL, L"Hello World", -1, &amp;rct, 0, fontColor );
      d3ddev-&gt;EndScene();
      d3ddev-&gt;Present(NULL, NULL, NULL, NULL);
  }
  
  void cleanD3D(void){
      d3ddev-&gt;Release();
      d3d-&gt;Release();
      i_buffer-&gt;Release();
      v_buffer-&gt;Release();
      ColorVertex::Decl-&gt;Release();
  }
  </code></pre>