一、初始化交换链
// DXGI交换链
DXGI_SWAP_CHAIN_DESC swapChainDesc;
// 清空内存
ZeroMemory( &swapChainDesc, sizeof( swapChainDesc ) );
swapChainDesc.BufferCount = 1;
swapChainDesc.BufferDesc.Width = 640;
swapChainDesc.BufferDesc.Height = 480;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; //图片格式
swapChainDesc.BufferDesc.RefreshRate.Numerator = 60; // 刷新率-分子
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;// 刷新率-分母
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.OutputWindow = g_hWnd; // 窗口句柄
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.Windowed = TRUE; // 抗锯齿
二、设置应用程序功能等级
D3D_FEATURE_LEVEL FeatureLevels = D3D_FEATURE_LEVEL_11_0;
三、创建Device
// 功能等级
D3D_FEATURE_LEVEL FeatureLevel;
if( FAILED (D3D11CreateDeviceAndSwapChain( NULL,
D3D_DRIVER_TYPE_REFERENCE, //Reference 设备
NULL,
0,
&FeatureLevels,
1,
D3D11_SDK_VERSION,
&sd,
&g_pSwapChain,
&g_pd3dDevice,
&FeatureLevel,
&g_pImmediateContext )))
{
return S_FALSE;
}