Directx ID3D11DeviceContext::DrawIndexed()失败
我的程序是Directx程序,它在更小的立方体中绘制一个容器立方体…这些更小的立方体在我希望你们理解我的意思的时候掉落 程序尚未完成…它应该只绘制容器…但它什么也不绘制…只有背景颜色可见。。。我只包含了我认为需要的内容… 这是初始化程序的例程Directx ID3D11DeviceContext::DrawIndexed()失败,directx,directx-11,Directx,Directx 11,我的程序是Directx程序,它在更小的立方体中绘制一个容器立方体…这些更小的立方体在我希望你们理解我的意思的时候掉落 程序尚未完成…它应该只绘制容器…但它什么也不绘制…只有背景颜色可见。。。我只包含了我认为需要的内容… 这是初始化程序的例程 bool Game::init(HINSTANCE hinst,HWND _hw){ Directx11 ::init(hinst , _hw); return LoadContent();} Directx11::init() bool Directx
bool Game::init(HINSTANCE hinst,HWND _hw){
Directx11 ::init(hinst , _hw);
return LoadContent();}
Directx11::init()
bool Directx11::init(HINSTANCE-hinst,HWND-hw){
_hinst=hinst;_-hwnd=hw;
RECT-rc;
GetClientRect(_-hwnd,&rc);
高度=钢筋混凝土底部-钢筋混凝土顶部;
宽度=右钢筋混凝土-左钢筋混凝土;
UINT标志=0;
#ifdef_调试
标志|=D3D11_创建_设备_调试;
#恩迪夫
HR(D3D11CreateDevice(0,驱动器类型,0,标志,0,0,D3D11,SDK版本,和d3dDevice,和功能级别,和d3dDeviceContext));
如果(d3dDevice==0 | | d3dDeviceContext==0)
返回0;
DXGI交换链描述sdesc;
零内存(&sdesc,sizeof(DXGI_SWAP_CHAIN_DESC));
sdesc.Windowed=true;
sdesc.BufferCount=1;
sdesc.BufferDesc.Format=DXGI_Format_R8G8B8A8_UNORM;
sdesc.BufferDesc.Height=高度;
sdesc.BufferDesc.Width=宽度;
sdesc.BufferDesc.Scaling=DXGI_MODE_Scaling_未指定;
sdesc.BufferDesc.ScanlineOrdering=DXGI\u MODE\u SCANLINE\u ORDER\u未指定;
输出窗口=_hwnd;
sdesc.BufferDesc.RefreshRate.分母=1;
sdesc.BufferDesc.RefreshRate.Numerator=60;
sdesc.Flags=0;
sdesc.BufferUsage=DXGI\u USAGE\u RENDER\u TARGET\u输出;
如果(M4XMSAA启用)
{
sdesc.SampleDesc.Count=4;
sdesc.SampleDesc.Quality=m4xMsaaQuality-1;
}
其他的
{
sdesc.SampleDesc.Count=1;
sdesc.SampleDesc.Quality=0;
}
IDxgDevice*设备=0;
HR(D3D设备->查询接口(uuuuiDof(IDXGIDevice),重新解释转换(&Device));
IDXGIAdapter*Ad=0;
HR(设备->获取父项(uuu-uuidof(IDXGIAdapter),重新解释演员表(&Ad));
IDXGIFactory*fac=0;
HR(Ad->GetParent(uuuuidof(IDXGIFactory),重新解释演员阵容(&fac));
fac->CreateSwapChain(d3dDevice,&sdesc,&swapchain);
ReleaseCOM(设备);
ReleaseCOM(Ad);
新闻发布公司(fac);
ID3D11Texture2D*back=0;
HR(swapchain->GetBuffer(0,uu-uuidof(ID3D11Texture2D),重新解释投射(&back));
HR(d3dDevice->CreateRenderTargetView(后退、0和RenderTarget));
D3D11_纹理2D_描述Tdesc;
零内存(&Tdesc,sizeof(D3D11_TEXTURE2D_DESC));
Tdesc.BindFlags=D3D11_BIND_DEPTH_模具;
Tdesc.ArraySize=1;
Tdesc.Format=DXGI\u Format\u D24\u UNORM\u S8\u UINT;
Tdesc.高度=高度;
Tdesc.宽度=宽度;
Tdesc.Usage=D3D11\u Usage\u默认值;
Tdesc.MipLevels=1;
如果(M4XMSAA启用)
{
Tdesc.SampleDesc.Count=4;
Tdesc.SampleDesc.Quality=m4xMsaaQuality-1;
}
其他的
{
Tdesc.SampleDesc.Count=1;
Tdesc.SampleDesc.Quality=0;
}
HR(d3dDevice->CreateTexture2D(&Tdesc,0和depthview));
HR(d3dDevice->CreateDepthStencilView(depthview,0和深度));
d3dDeviceContext->OMSetRenderTargets(1,&RenderTarget,深度);
D3D11_视口vp;
vp.TopLeftX=0.0f;
vp.TopLeftY=0.0f;
vp.宽度=静态铸件(宽度);
vp.高度=静态铸件(高度);
vp.MinDepth=0.0f;
vp.MaxDepth=1.0f;
d3dDeviceContext->RSSET视口(1,&vp);
返回true;
SetBuild()在容器中为较小的立方体准备矩阵……我还没有编程来绘制较小的立方体
这就是绘制场景的功能
void Game::Render(){
d3dDeviceContext->ClearRenderTargetView(RenderTarget,reinterpret_cast <const float*> (&Colors::LightSteelBlue));
d3dDeviceContext->ClearDepthStencilView(depth,D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL,1.0f,0);
d3dDeviceContext-> IASetInputLayout(_layout);
d3dDeviceContext-> IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
d3dDeviceContext->IASetIndexBuffer(indices,DXGI_FORMAT_R32_UINT,0);
UINT strides=sizeof(Vertex),off=0;
d3dDeviceContext->IASetVertexBuffers(0,1,&vertices,&strides,&off);
D3DX11_TECHNIQUE_DESC des;
Tech->GetDesc(&des);
Floor * Lookup; /*is a variable to Lookup inside the matrices structure (Floor Contains XMMATRX Piese[9])*/
std::vector<XMFLOAT4X4> filled; // saves the matrices of the smaller cubes
XMMATRIX V=XMLoadFloat4x4(&View),P = XMLoadFloat4x4(&Proj);
XMMATRIX vp = V * P;XMMATRIX wvp;
for (UINT i = 0; i < des.Passes; i++)
{
d3dDeviceContext->RSSetState(BuildRast);
wvp = XMLoadFloat4x4(&(B.Memory[0].Pieces[0])) * vp; // Loading The Matrix at translation(0,0,0)
HR(ShadeMat->SetMatrix(reinterpret_cast<float*> ( &wvp)));
HR(Tech->GetPassByIndex(i)->Apply(0,d3dDeviceContext));
d3dDeviceContext->DrawIndexed(build_ind_count,build_ind_index,build_vers_index);
d3dDeviceContext->RSSetState(PieseRast);
UINT r1=B.GetSize(),r2=filled.size();
for (UINT j = 0; j < r1; j++)
{
Lookup = &B.Memory[j];
for (UINT r = 0; r < Lookup->filledindeces.size(); r++)
{
filled.push_back(Lookup->Pieces[Lookup->filledindeces[r]]);
}
}
for (UINT j = 0; j < r2; j++)
{
ShadeMat->SetMatrix( reinterpret_cast<const float*> (&filled[i]));
Tech->GetPassByIndex(i)->Apply(0,d3dDeviceContext);
d3dDeviceContext->DrawIndexed(piese_ind_count,piese_ind_index,piese_vers_index);
}
}
HR(swapchain->Present(0,0));}
void Game::Render(){
d3dDeviceContext->ClearRenderTargetView(RenderTarget,reinterpret_cast(&Colors::LightSteelBlue));
D3dDeviceText->ClearDepthStencilView(深度,D3D11_CLEAR_depth | D3D11_CLEAR_STENCIL,1.0f,0);
d3dDeviceContext->IASetInputLayout(_layout);
D3dDeviceText->iSetPrimitiveTopology(D3D10_Primitiver_TOPOLOGY_TRIANGLELIST);
d3dDeviceContext->IASetIndexBuffer(索引,DXGI格式,R32单元,0);
UINT步幅=顶点大小,关闭=0;
d3dDeviceContext->IASetVertexBuffers(0,1,&顶点,&跨步,&关闭);
D3DX11_技术描述;
技术->获取描述(&des);
Floor*Lookup;/*是在矩阵结构中查找的变量(Floor包含XMMATRX Piese[9])*/
std::vector filled;//保存较小立方体的矩阵
XMMATRIX V=XMLoadFloat4x4(&View),P=XMLoadFloat4x4(&Proj);
XMMATRIX vp=V*P;XMMATRIX wvp;
对于(UINT i=0;iRSSetState(BuildRast);
wvp=XMLoadFloat4x4(&(B.Memory[0].Pieces[0]))*vp;//在转换时加载矩阵(0,0,0)
HR(ShadeMat->SetMatrix(重新解释投射(&wvp));
HR(Tech->GetPassByIndex(i)->Apply(0,d3ddevicontext));
d3dDeviceContext->DrawIndexed(构建索引计数、构建索引、构建版本索引);
d3dDeviceContext->RSSetState(PieseRast);
UINT r1=B.GetSize(),r2=filled.size();
对于(UINT j=0;jfilledDeces.size();r++)
{
填充。向后推(查找->块[查找->填充的块[r]]);
}
}
对于(UINT j=0;jSetMatrix(重新解释和填充[i]);
Tech->GetPassByIndex(i)->Apply(0,d3ddevicontext);
d3dDeviceContext->DrawIndexed(piese_ind_count、piese_ind_index、piese_vers_index);
}
}
HR(swapchain->Present(0,0));}
提前感谢您程序中的一个错误似乎是您正在使用当前过程的索引
i
,作为填充的
向量的索引,而您显然应该使用j
另一个明显的错误是,在循环中,您应该迭代filled
的元素,而不是迭代所有元素。值r2
被设置为filled
的大小,然后在该过程中向其添加任何内容。在第一次过程中,这意味着该元素不会绘制任何内容如果您的技术只有一个过程,那么这意味着代码中的第二个DrawIndexed
调用将永远不会执行
你也应该只添加一个矩阵给void Game::Render(){
d3dDeviceContext->ClearRenderTargetView(RenderTarget,reinterpret_cast <const float*> (&Colors::LightSteelBlue));
d3dDeviceContext->ClearDepthStencilView(depth,D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL,1.0f,0);
d3dDeviceContext-> IASetInputLayout(_layout);
d3dDeviceContext-> IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
d3dDeviceContext->IASetIndexBuffer(indices,DXGI_FORMAT_R32_UINT,0);
UINT strides=sizeof(Vertex),off=0;
d3dDeviceContext->IASetVertexBuffers(0,1,&vertices,&strides,&off);
D3DX11_TECHNIQUE_DESC des;
Tech->GetDesc(&des);
Floor * Lookup; /*is a variable to Lookup inside the matrices structure (Floor Contains XMMATRX Piese[9])*/
std::vector<XMFLOAT4X4> filled; // saves the matrices of the smaller cubes
XMMATRIX V=XMLoadFloat4x4(&View),P = XMLoadFloat4x4(&Proj);
XMMATRIX vp = V * P;XMMATRIX wvp;
for (UINT i = 0; i < des.Passes; i++)
{
d3dDeviceContext->RSSetState(BuildRast);
wvp = XMLoadFloat4x4(&(B.Memory[0].Pieces[0])) * vp; // Loading The Matrix at translation(0,0,0)
HR(ShadeMat->SetMatrix(reinterpret_cast<float*> ( &wvp)));
HR(Tech->GetPassByIndex(i)->Apply(0,d3dDeviceContext));
d3dDeviceContext->DrawIndexed(build_ind_count,build_ind_index,build_vers_index);
d3dDeviceContext->RSSetState(PieseRast);
UINT r1=B.GetSize(),r2=filled.size();
for (UINT j = 0; j < r1; j++)
{
Lookup = &B.Memory[j];
for (UINT r = 0; r < Lookup->filledindeces.size(); r++)
{
filled.push_back(Lookup->Pieces[Lookup->filledindeces[r]]);
}
}
for (UINT j = 0; j < r2; j++)
{
ShadeMat->SetMatrix( reinterpret_cast<const float*> (&filled[i]));
Tech->GetPassByIndex(i)->Apply(0,d3dDeviceContext);
d3dDeviceContext->DrawIndexed(piese_ind_count,piese_ind_index,piese_vers_index);
}
}
HR(swapchain->Present(0,0));}