1 Environment Installation Download DirectX10.
Follow the prompts to install, and my installation path is C: Program Files Microsoft DirectX SDK (June 2010). Create a blank Win32 application in VS2013. Set in project properties:
Include directory
C: Program Files (x86) Microsoft DirectX SDK (June 2010) Include
Library directory
C: Program Files (x86) Microsoft DirectX SDK (June 2010) Lib x86
Add additional dependency lib file under linker options
Add the following lib file
D3d9. lib
D3dx10d. lib
D3dx9d. lib
Dxerr. lib
Dxguid. lib
Winmm. lib
Comctl32. lib
.
The first DirectX program - initialization of Direct3D
Firstly, obtain a pointer to the interface:
if (NULL == (g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)))
return E_FAIL; //if the acquisition fails, an error message will be returned
Next, fill in D3DPRESENT_ PARAMETRS structure.
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
The 'Window' indicates whether it is full screen, and if it is FALSE, it is full screen; SwapEffect is a member of the D3DSWAPEFFECT enumeration type that specifies the page replacement method cached in the swap chain. Exchange chains typically consist of two surfaces (pixel matrices representing two-dimensional image data). One serves as a front-end cache for displaying images on the monitor; One serves as a backend cache for applications to draw images, and the two surfaces exchange with each other to display the drawn images at a frame rate.
Then create the device.
if (FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice)))
{
return E_FAIL;
}
G_ Pd3dDevice is a device created for subsequent image drawing and rendering.
The source code for initializing Direct3D is located in the installation directory: C: Program Files Microsoft DirectX SDK (June2010) Samples C++ Direct3D Tutorials Tut01_ Copy the Create Device. cpp file under Create Device to your program to run it.