Visual Studio 本身不內建 DirectX SDK。 DirectX 執行階段元件隨 Windows 作業系統提供,但開發所需的標頭檔、庫檔、工具(如效能分析器 PIX)需另行安裝 DirectX SDK 或使用 Windows SDK。
| 作業系統 | 內建 DirectX 版本 | 備註 |
|---|---|---|
| Windows XP SP3 | DirectX 9.0c | 需另裝 DirectX 9.0c SDK 開發 |
| Windows 7 / Server 2008 R2 | DirectX 11.0 | 含 Direct3D 11、DXGI 1.1 |
| Windows 8 / Server 2012 | DirectX 11.1 | 新增 Direct2D 1.1、WARP 改進 |
| Windows 8.1 / Server 2012 R2 | DirectX 11.2 | 資源平鋪、HDR 支援 |
| Windows 10 / Server 2016+ | DirectX 12 | 低階 API、DirectX Raytracing (DXR) |
$(WindowsSDK_IncludePath)。$(WindowsSDK_LibraryPath_x86) 或 $(WindowsSDK_LibraryPath_x64)。d3d11.lib;dxgi.lib;d3dcompiler.lib;dxguid.lib 等。#include 、#include 等。$(DXSDK_DIR)Include$(DXSDK_DIR)Lib\x86 (或 x64)#include
#include
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "dxgi.lib")
int main() {
ID3D11Device* pDevice = nullptr;
ID3D11DeviceContext* pContext = nullptr;
D3D_FEATURE_LEVEL featureLevel;
HRESULT hr = D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, 0, nullptr, 0,
D3D11_SDK_VERSION, &pDevice, &featureLevel, &pContext);
if (SUCCEEDED(hr)) {
printf("Direct3D 11 初始化成功,Feature Level: %d\n", featureLevel);
pDevice->Release();
pContext->Release();
} else {
printf("初始化失敗: 0x%08X\n", hr);
}
return 0;
}
$(DXSDK_DIR) 相關設定,改用 Windows SDK 路徑,並更新標頭檔包含順序(Windows SDK 優先)。v120_xp (VS2013) 或 v140_xp (VS2015+),並使用 DirectX 11.0 API,避免使用 11.1+ 功能。d3dx11.h、D3DX11CreateDevice 等輔助函數?$(DXSDK_DIR) 路徑正確,並注意版本衝突。