我在获得一个索引缓冲区以正确显示一些导入的.obj时遇到了问题。它被考虑到了坐标系的方向。( obj加载程序是硬编码的)可以很好地打印索引,因此它正确地填充了要读取和设置的DWORD数组:
vector < vector <float> > index;
index = GetObjData(FilePath, VERTEXINDEXLIST);
for (int n=0; n<index.size(); n++){
m=m+index[n].size();
}..。
DWORD *IndexBuffer = new DWORD[m];..。
iBufferDescription.Usage =D3D11_USAGE_DEFAULT;
iBufferDescription.ByteWidth =sizeof(DWORD)*m;
iBufferDescription.BindFlags =D3D11_BIND_INDEX_BUFFER;
iBufferDescription.CPUAccessFlags =0;
iBufferDescription.MiscFlags =0;
D3D11_SUBRESOURCE_DATA iSRData;
iSRData.pSysMem=IndexBuffer;
Device->CreateBuffer(&iBufferDescription, &iSRData, &D3DIndexBuffer);
DeviceContext->IASetIndexBuffer(D3DIndexBuffer, DXGI_FORMAT_R16_UINT, 0);下面是玛雅生成的.obj:
# This file uses centimeters as units for non-parametric coordinates.
mtllib tbox.mtl
g default
v -0.500000 -0.500000 -0.000000
v 0.500000 -0.500000 -0.000000
v -0.500000 0.500000 0.000000
v 0.500000 0.500000 0.000000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 0.000000 1.000000
vt 1.000000 1.000000
vn 0.000000 -0.000000 1.000000
vn 0.000000 -0.000000 1.000000
vn 0.000000 -0.000000 1.000000
vn 0.000000 -0.000000 1.000000
s 1
g pPlane1
usemtl initialShadingGroup
f 1/1/1 2/2/2 3/3/3
f 3/3/3 2/2/2 4/4/4一个带有4 vertices.Passed的2D正方形通过该函数,DWORD IndexBuffer的内容如下:
2
1
0
3
1
2(-1从所有索引中,为了符合DirectX),我还将补充一些其他设置,如ID3D11RasterizerState。
D3D11_RASTERIZER_DESC DrawStyleState;
DrawStyleState.AntialiasedLineEnable=true;
DrawStyleState.CullMode=D3D11_CULL_NONE;
DrawStyleState.DepthBias=0;
DrawStyleState.FillMode=D3D11_FILL_SOLID;
DrawStyleState.DepthClipEnable=true;
DrawStyleState.MultisampleEnable=true;
DrawStyleState.FrontCounterClockwise=false;
DrawStyleState.ScissorEnable=false;
ID3D11RasterizerState *DS_State;
Device->CreateRasterizerState(&DrawStyleState, &DS_State);
DeviceContext->RSSetState(DS_State);最后,呈现函数是相当标准的:
void Render(){
float ColorBlue[] = {0.3f,0.3f,1.0f,1.0f};
DeviceContext->ClearRenderTargetView(RenderTargetView,ColorBlue);
UINT stride=sizeof(VERTEX);
UINT Offset=0;
DeviceContext->IASetVertexBuffers(0,1,&D3DBuffer,&stride,&Offset);
DeviceContext->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
DeviceContext->DrawIndexed(IndSz,0,0);
Swapchain->Present(0,0);
}对于索引大小,IndSz是全局的。这是正确的:我为它创建了一个调试器,给出了反馈:
4 vertices
6 index array size //element size = IndSz
Index 0: 2
Index 1: 1
Index 2: 0
Index 3: 3
Index 4: 1
Index 5: 2上面的这些被解析成一个三角形。
|\
| \
| \
| \
------我的结论是,这可能是另一个问题,而不是我能想到的。我已经检查了筛选问题,排序,数据类型有趣,内存大小疯狂,它现在似乎接近重写。帮助!
发布于 2014-01-17 08:31:46
DWORD不会随着你的CPU的单词大小而改变,就像这听起来一样有趣。DWORD是总是32位的,无论是在Windows上的主机CPU,它实际上是微软的uint32_t。另一方面,UINT非常模糊,并且可能随着CPU字的大小而改变。顺便说一句,与DXGI_FORMAT_R16_UINT配对的适当数据类型实际上是WORD (16位)。
但是,这里的实际问题似乎是D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP的使用。你展示的进口模型由两个面组成,三角形条中的六个顶点将产生四个面。
你想要D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST,如果这6个指数被认为能产生精确的两个三角形。
https://stackoverflow.com/questions/21153549
复制相似问题