title: Very high CPU usage directx 9
body: <p>I'm going to use DirectX, so I'm using directxtutorial.com tutorial. When I run my game, it has very high cpu usage. It takes all power of the first core of my processor. I have Celeron e3400. I think it's much more than I need to run my game without anything. </p>
  
  <p>Sorry for that bunch of code. I have no idea what could be wrong.
  Here is my code:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;windowsx.h&gt;
  #include &lt;d3d9.h&gt;
  
  #pragma (lib, "d3d9.lib")
  
  #define Width_X 1024
  #define Height_Y 768
  
  
  LPDIRECT3D9 d3d;
  LPDIRECT3DDEVICE9 d3d_device;
  
  void d3d_initialize(HWND hWnd);
  void render_frame();
  void d3d_clear();
  
  void d3d_initialize(HWND hWnd)
  {
  d3d = Direct3DCreate9(32); // value for dx9 = 32, i think
  D3DPRESENT_PARAMETERS d3dpp;
  
  ZeroMemory(&amp;d3dpp,sizeof(d3dpp));
  d3dpp.Windowed = false;
  d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
  d3dpp.hDeviceWindow = hWnd;
  d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;    // set the back buffer format to 32-bit
  d3dpp.BackBufferWidth = Width_X;    // set the width of the buffer
  d3dpp.BackBufferHeight = Height_Y;
  
  d3d-&gt;CreateDevice(D3DADAPTER_DEFAULT,
                    D3DDEVTYPE_HAL,
                    hWnd,
                    D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                    &amp;d3dpp,
                    &amp;d3d_device);
  }
  
  void render_frame()
  {
  d3d_device-&gt;Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(54, 222, 10), 1.0f, 0);
  d3d_device-&gt;BeginScene();
  
  
  d3d_device-&gt;EndScene();
  d3d_device-&gt;Present(NULL, NULL, NULL, NULL);
  }
  
  void cleanD3D(void)
  {
  d3d_device-&gt;Release();    // close and release the 3D device
  d3d-&gt;Release();    // close and release Direct3D
  }
  
  
  LRESULT CALLBACK WindowProc(HWND hWnd,
                       UINT message,
                       WPARAM wParam,
                       LPARAM lParam);
  
  int WINAPI WinMain(HINSTANCE hInstance,
                 HINSTANCE hPrevInstance,
                 LPSTR lpCmdLine,
                 int nCmdShow)
  {
  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.hbrBackground = (HBRUSH)COLOR_WINDOW;
  wc.lpszClassName = "WindowClass1";
  
  RegisterClassEx(&amp;wc);
  
  hWnd = CreateWindowExW(NULL,
                        L"WindowClass1",    // name of the window class
                        L"Test",   // title of the window
                        WS_EX_TOPMOST ,//| WS_POPUP, // window style //
                        0,    // x-position of the window
                        0,    // y-position of the window
                        Width_X,    // width of the window
                        Height_Y,    // height of the window
                        NULL,    // we have no parent window, NULL
                        NULL,    // we aren't using menus, NULL
                        hInstance,    // application handle
                        NULL);    // used with multiple windows, NULL
  
  ShowWindow(hWnd, nCmdShow);
  d3d_initialize(hWnd);
  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();
      }
          return msg.wParam;
          cleanD3D();
  }
  
  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);
  }
  </code></pre>