DirectX environment configuration

  • Tags : directx
  • time :

DirectX Learning.

First demo.

1. DirectX environment configuration under vs.

(1) Download and install DirectX SDK.

(2) Configure the directory and reference directory in VS.

SDK installation directory: C: Program Files (x86) Microsoft DirectX SDK (June 2010).

Include directory: C: Program Files (x86) Microsoft DirectX SDK (June 2010) Include.

Reference directory: C: Program Files (x86) Microsoft DirectX SDK (June 2010) Lib x86.

2. DirectX initialization steps.

(1) Initialize COM objects.

PD3D= Direct3DCreate9 (D3D_SDK VERSION);

(2) Obtain hardware information.

D3DCAPS9 caps;

Int vp= 0.

If (FAILED (pD3D -->GetDeviceCaps (D3DAPTER-DEFAULT, D3DDEVTYPE-HAL,& caps))) {.

Return false;

}.

(3) Create objects.

//Create device.

If (FAILED (pD3D -> Create Device (D3DAPTER-DEFAULT, D3DDEVTYPEHAL, hwnd, vp,& d3dpp,& g_pd3dDevice)) {.

Return false;

}.

Objects_ Init()// Initialize rendering parameters.

(4) Graphic rendering.

//1. Clear screen operation.

If (FAILED (g_pd3dDevice -> Clear (0, NULL, D3DCLEAR-TARGET, D3DCOLOR_XRGB (0, 0, 0), 1.0f, 0))) {.

Return;

}.

//2. Start scene.

If (FAILED (g_pd3dDevice -> BeginScene())) {.

Return;

}.

//3. Formal drawing.

If (FAILED (D3DXCreatFont (g_pd3dDevice, 25, 12, 0, D3DX-DEFAULT, false, DEFAULT-CHARSET, OUT-DEFAULT-PRECIS, DEFAULT-QUALITY, 0, L" MEPIX",& font)) {.

Return;

}.

RECT fontPosition;

FontPosition. top= 20;

FontPosition. bottom= 200;

FontPosition. right= 200;

FontPosition. left= 20;

Font -> DrawText (0, L" Hello world!", -1,& fontPosition, DT-CENTER | DT_VCENTER, D3DCOLOR_XRGB (255 * rand(), 255 * rand(), 255 * rand());

//4. End scene.

If (FAILED (g_pd3dDevice -> EndScene())) {.

Return;

}.

//5. Flip display.

G_ Pd3dDevice -> Present (NULL, NULL, NULL, NULL);

(5) Clear.

PD3D --> Release();