I'm creating a game and was looking to draw a cube in window. I completed a working function that fills a VERTEX
structure with an obj file's vertex content. However, passing the output structure into the buffer seems to output 1 to 2 visible vertices (under D3D_PRIMITIVE_TOPOLOGY_POINTLIST
, for debugging purposes) while the entire structure is printable.
Since I'm passing in raw vertices, is there something else I need to know?
(Using DX11)
(Triangles are drawn. Squares seem to draw a triangle.(Under D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP
))
EDIT:
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.
Vertice are brought in,
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);
}
Data is rendered:
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);
}