0
我正在創建一個遊戲,並且正在尋找在窗口中繪製一個立方體。我完成了一個工作函數,用obj文件的頂點內容填充VERTEX
結構。但是,將輸出結構傳遞到緩衝區似乎輸出1到2個可見的頂點(出於調試目的,在D3D_PRIMITIVE_TOPOLOGY_POINTLIST
下),而整個結構是可打印的。DirectX:從結構數組中繪製一個立方體
由於我在傳遞原始頂點,還有什麼我需要知道的嗎? (使用DX11)
(三角形繪製方似乎畫一個三角形(下D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP
)。)
編輯:
objv= GetObjData(FilePath, 1);
VERTEX *Cup = new VERTEX[objv.size()];
Cup = CreateVertexDS(objv, 1.0f, 1.0f, 1.0f, 1.0f);
int Cupsize=objv.size();
ObjSz=Cupsize; //Debugging purposes, sets a global variable: # of array elements.
頂點都帶來了,
D3D11_BUFFER_DESC BufferDescription;
ZeroMemory(&BufferDescription, sizeof(BufferDescription));
BufferDescription.Usage =D3D11_USAGE_DYNAMIC;
BufferDescription.ByteWidth =sizeof(VERTEX)*ObjSz; //# of element from obj file.
BufferDescription.BindFlags =D3D11_BIND_VERTEX_BUFFER;
BufferDescription.CPUAccessFlags =D3D11_CPU_ACCESS_WRITE;
BufferDescription.MiscFlags =0;
D3D11_SUBRESOURCE_DATA SRData;
ZeroMemory(&SRData, sizeof(SRData));
SRData.pSysMem=⋓
Compile_Monitor = Device->CreateBuffer(&BufferDescription, &SRData, &D3DBuffer);
if(FAILED(Compile_Monitor))
{
MessageBox(hWnd, L"CreateBuffer() failed. Check for: \n Possible Bad or NULL value in D3D11_BUFFER_DESC struct.",
L"Program Error!",
MB_OK);
PostQuitMessage(0);
}
D3D11_MAPPED_SUBRESOURCE MappedResource;
Compile_Monitor = DeviceContext->Map(D3DBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &MappedResource);
if(FAILED(Compile_Monitor))
{
MessageBox(hWnd, L"Map() failed.",
L"Program Error!",
MB_OK);
PostQuitMessage(0);
}
memcpy(MappedResource.pData, &Cup, sizeof(Cup));
DeviceContext->Unmap(D3DBuffer, NULL);
}
數據顯示:
void Render(){
float ColorBlue[] = {0.4f,0.4f,0.4f,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_POINTLIST);
DeviceContext->Draw(ObjSz,0);
Swapchain->Present(0,0);
}
我已更新,以添加更多信息。 –
你是先生,是透視和知識。您的鏈接讓位給頂點排序的簡要說明:Maya的右手座標系與Directx格式。我將在代碼中實現它並檢查結果。 –
@InfinityMachine我以前從來沒有被稱爲clairvoyant。我必須看看:) – Proxy