Directx 11 D3d初始化,创建交换链出错,帮忙诊断下?

wangming24 2013-11-22 05:57:06
// 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交换链失败!",搞了一个下午,不知道出错在哪里?
...全文
311 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

8,304

社区成员

发帖
与我相关
我的任务
社区描述
游戏开发相关内容讨论专区
社区管理员
  • 游戏开发
  • 呆呆敲代码的小Y
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧