void InitD3D(HWND hWnd) { g_lpD3D = Direct3DCreate8(D3D_SDK_VERSION); if (!g_lpD3D){ InitFail(hWnd,"Failed to create Direct3D"); return; } g_hWnd = hWnd; g_dwWindowStyle = GetWindowLong( hWnd, GWL_STYLE ); GetWindowRect( hWnd, &g_rcWindowBounds ); GetClientRect( hWnd, &g_rcWindowClient ); g_lpDevices = new CDeviceInformation(g_lpD3D, g_bUseDepthBuffer, g_dwMinDepthBits, g_dwMinStencilBits,NULL); if ((NULL == g_lpDevices)||( NULL == (g_Adapters = g_lpDevices->getAdapters()))) { InitFail(hWnd, "BuildDeviceList Failed."); return; } g_dwNumAdapters = g_lpDevices->getNumAdapters(); g_dwAdapter = g_lpDevices->getCurrentAdapter(); // Create device with hardware geometry engine. if (FAILED(::Initialize3DEnvironment(hWnd))){ InitFail(hWnd, "CreateDevice Failed."); return; } if (FAILED(g_lpD3DDEV->GetDeviceCaps(&g_CurrentDeviceCaps))){ InitFail(hWnd, "GetDeviceCaps Failed."); return; } g_bCanGreaterEqual = false; if (g_CurrentDeviceCaps.AlphaCmpCaps & D3DPCMPCAPS_GREATEREQUAL) g_bCanGreaterEqual = true; g_pHighResTimer = new CHighResTimer(); }
冒頭部分つまり、下のリストの部分は、まずは、LPDIRECT3D8 型のインターフェイスを取得している。
g_lpD3D = Direct3DCreate8(D3D_SDK_VERSION); if (!g_lpD3D){ InitFail(hWnd,"Failed to create Direct3D"); return; }
続いて次の部分を見てみよう。
g_hWnd = hWnd; g_dwWindowStyle = GetWindowLong( hWnd, GWL_STYLE ); GetWindowRect( hWnd, &g_rcWindowBounds ); GetClientRect( hWnd, &g_rcWindowClient );
続いて次の部分。
g_lpDevices = new CDeviceInformation(g_lpD3D, g_bUseDepthBuffer, g_dwMinDepthBits, g_dwMinStencilBits,NULL);
CDeviceInformation.cpp
CDeviceInformation.h
次の部分。
if ((NULL == g_lpDevices)||( NULL == (g_Adapters = g_lpDevices->getAdapters()))) { InitFail(hWnd, "BuildDeviceList Failed."); return; } g_dwNumAdapters = g_lpDevices->getNumAdapters(); g_dwAdapter = g_lpDevices->getCurrentAdapter();
次の部分。
// Create device with hardware geometry engine. if (FAILED(::Initialize3DEnvironment(hWnd))){ InitFail(hWnd, "CreateDevice Failed."); return; }
if (FAILED(g_lpD3DDEV->GetDeviceCaps(&g_CurrentDeviceCaps))){ InitFail(hWnd, "GetDeviceCaps Failed."); return; }
g_bCanGreaterEqual = false; if (g_CurrentDeviceCaps.AlphaCmpCaps & D3DPCMPCAPS_GREATEREQUAL) g_bCanGreaterEqual = true;
g_pHighResTimer = new CHighResTimer();