Directx 11 D3d初始化,创建交换链出错,帮忙诊断下?
// try.cpp : 定义应用程序的入口点。
#include "stdafx.h"
#include "try.h"
#include "assert.h"
#include "d3d11.h"
//----------------------------------------------------------------------------
HWND hWnd;
ID3D11Device *g_device = 0;
ID3D11DeviceContext *g_deviceContext = 0;
IDXGISwapChain *g_swapChain=0 ;
ID3D11DepthStencilView *g_depthStencilView = 0;
ID3D11RenderTargetView *g_renderTargetView = 0;
//--------------Direct3D11初始化一:创建设备和设备上下文-------------------------------BOOL kais()
{
D3D_DRIVER_TYPE driverTypes[] ={
D3D_DRIVER_TYPE_HARDWARE,
D3D_DRIVER_TYPE_WARP,
D3D_DRIVER_TYPE_REFERENCE,
D3D_DRIVER_TYPE_SOFTWARE,
D3D_DRIVER_TYPE_UNKNOWN
};
unsigned int totalDriverTypes = sizeof( driverTypes );
D3D_FEATURE_LEVEL featureLevels[] = {
D3D_FEATURE_LEVEL_9_1,
D3D_FEATURE_LEVEL_9_2,
D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_11_0
};
D3D_FEATURE_LEVEL myFeatureLevel;
HRESULT hr;
hr= D3D11CreateDevice( NULL, D3D_DRIVER_TYPE_HARDWARE, 0, 0, featureLevels, 4, D3D11_SDK_VERSION, &g_device, &myFeatureLevel, &g_deviceContext);
if(FAILED(hr))
{
MessageBox(NULL, L"创建d3d11设备失败!", L"错误", MB_OK);
return FALSE;
}
//----------------------------------------------------------------------------------UINT msaa4xQuality(0);
g_device->CheckMultisampleQualityLevels(DXGI_FORMAT_R8G8B8A8_UNORM,4,&msaa4xQuality);
assert(msaa4xQuality > 0);
//----------------------------------------------------------------------------------
//--------------Direct3D11初始化三:创建交换链------------------------------------
RECT rc;
GetClientRect( hWnd, &rc );
UINT width = rc.right - rc.left;
UINT height = rc.bottom - rc.top;
DXGI_SWAP_CHAIN_DESC scDesc;
ZeroMemory( &scDesc, sizeof(scDesc));
scDesc.BufferCount=1;
scDesc.BufferDesc.Width = width; //缓冲区宽度
scDesc.BufferDesc.Height = height;
scDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
scDesc.BufferDesc.RefreshRate.Numerator = 60; //刷新率
scDesc.BufferDesc.RefreshRate.Denominator = 1;
scDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
scDesc.OutputWindow = hWnd;
scDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
scDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
scDesc.SampleDesc.Count = 4;
scDesc.SampleDesc.Quality = msaa4xQuality - 1;
scDesc.Windowed = true;
scDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
scDesc.Flags = 0;
//---------------------------------------------------------------------------------//---------------------------获取IDXGIFactory以创建交换链
IDXGIDevice *dxgiDevice(NULL);
g_device->QueryInterface(__uuidof(IDXGIDevice),reinterpret_cast<void**>(&dxgiDevice));
IDXGIAdapter *dxgiAdapter(NULL);
dxgiDevice->GetParent(__uuidof(IDXGIAdapter),reinterpret_cast<void**>(&dxgiAdapter));
IDXGIFactory *dxgiFactory(NULL);
dxgiAdapter->GetParent(__uuidof(IDXGIFactory),reinterpret_cast<void**>(&dxgiFactory));
hr= dxgiFactory->CreateSwapChain(g_device, &scDesc, &g_swapChain);
if(FAILED(hr))
{
MessageBox(NULL,L"创建d3d11交换链失败!",L"错误",MB_OK);
return FALSE;
} dxgiFactory->Release();
dxgiAdapter->Release();
dxgiDevice->Release();
//----------------------------------------------------------------------------------
return true;
}
问题:这段初始化,创建交换链出错:创建d3d11交换链失败!",搞了一个下午,不知道出错在哪里?