Hi
I want display a model. but there is something wrong.
I use PIX to see what's wrong, and I find the data is malposition.
This is the data what my program drew
VTX IDX POSITION[0] POSITION[1] POSITION[2] POSITION[3] TEXCOORD[0] TEXCOORD[1]
0 1 0.453 0.78 0.14 1 61.198 -14.418
1 2 61.198 -14.418 0.453 1 0.653 -7.689
2 0 0.024 55.081 -2.898 1 0.453 0.78
but the correct one is:
VTX IDX POSITION[0] POSITION[1] POSITION[2] POSITION[3] TEXCOORD[0] TEXCOORD[1]
0 1 0.14 61.198 -14.418 1 0.453 0.653
1 2 -7.689 61.197 -11.877 1 0.39 0.653
2 0 0.024 55.081 -2.898 1 0.453 0.78
the issue start at index 1 POSITION[0] and POSITION[1],
They re-use index 0 TEXCOORD[0] and TEXCOORD[1],
And I see the input layout, it is correct.
SemanticName SemanticIndex Format InputSlot AlignedByteOffset InputSlotClass InstanceDataStepRate
POSITION 0 DXGI_FORMAT_R32G32B32_FLOAT 0 0 D3D11_INPUT_PER_VERTEX_DATA 0
TEXCOORD 0 DXGI_FORMAT_R32G32_FLOAT 0 12 D3D11_INPUT_PER_VERTEX_DATA 0
In the .fx file
struct VSInputTexture
{
float4 pos : POSITION;
float2 tex0 : TEXCOORD0;
};
I use a struct in c++
struct VertexTexStr
{
XMFLOAT3 pos;
XMFLOAT2 tex;
};
I used D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST and
create vertex buffer:
[source lang="cpp"]void RenderObject::CreateVertexBuffer()
{
try
{
D3D11_BUFFER_DESC bufferDesc;
ZeroMemory( &bufferDesc, sizeof( bufferDesc ) );
D3D11_SUBRESOURCE_DATA initData;
ZeroMemory( &initData, sizeof( initData ) );
VertexTexStr* tmpVertexTex=NULL;
bufferDesc.Usage=D3D11_USAGE_DEFAULT;
bufferDesc.BindFlags=D3D11_BIND_VERTEX_BUFFER;
bufferDesc.CPUAccessFlags=0;
bufferDesc.MiscFlags=0;
bufferDesc.StructureByteStride=0;
switch(m_mode)
{
case RenderWithCameraWithTexture:
bufferDesc.ByteWidth=sizeof(VertexTexStr)*m_vertices->size();
tmpVertexTex=new VertexTexStr[m_vertices->size()];
for(size_t i=0;i<m_vertices->size();i++)
{
tmpVertexTex.pos=(*m_vertices);
tmpVertexTex.tex=(*m_texs);
}
initData.pSysMem=tmpVertexTex;
sendMessage(MSG_CREATE_BUFFER,AuxGroupArgus(&bufferDesc,&initData,&m_verticesBuffer));
delete[] tmpVertexTex;
break;[/source]
I use debug to see the initData.pSysMem, it is ok at index 1.
What's wrong?