See the question and my original answer on StackOverflow

You're missing quite a number of things for the cube to display:

  • You use DrawIndexed but you don't set any index buffer in the render pipeline (enable the DirectX Debug Layer and you will see a warning about this)
  • You must set the Rasterizer State in the pipeline

So for example you can add this to your code:

ID3D11Buffer* gp_IBuffer;
ID3D11RasterizerState* gp_rs;

// this goes in InitGraphics/Pipeline

// create an Index Buffer
D3D11_BUFFER_DESC ib{}
ib.Usage = D3D11_USAGE_IMMUTABLE;
ib.ByteWidth = sizeof(WORD) * ARRAYSIZE(CubeIndices);
ib.BindFlags = D3D11_BIND_INDEX_BUFFER;

D3D11_SUBRESOURCE_DATA data{};
data.pSysMem = CubeIndices;
gp_Device->CreateBuffer(&ib, &data, &gp_IBuffer);

// create a Rasterizer State
D3D11_RASTERIZER_DESC rasterizerDesc{};
rasterizerDesc.FillMode = D3D11_FILL_SOLID;
rasterizerDesc.CullMode = D3D11_CULL_NONE; // or something else
gp_Device->CreateRasterizerState(&rasterizerDesc, &gp_rs);

// this goes in Render()

gp_DeviceContext->IASetIndexBuffer(gp_IBuffer, DXGI_FORMAT_R16_UINT, 0);
gp_DeviceContext->RSSetState(gp_rs);

And you should see this:

enter image description here

PS: in general, you should set all pipeline actions (VSSetShader, PSSetShader, IASetInputLayout, OMSetRenderTargets, etc.) in the "render loop".