后面的 DirectX11 顶点被绘制在前面

DirectX11 Vertices behind getting drawn in front

我一直在关注一些 Rastertek 教程,但遇到了一个问题,即未正确绘制顶点。后面的顶点被绘制在应该在前面的顶点前面。我不确定为什么会这样,因为我相信一切都设置正确。

这是我的深度模板:

    D3D11_DEPTH_STENCIL_DESC dsd;
    ZeroMemory(&dsd, sizeof(dsd));

    dsd.DepthEnable = true;
    dsd.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
    dsd.DepthFunc = D3D11_COMPARISON_LESS;

    dsd.StencilEnable = true;
    dsd.StencilReadMask = 0xFF;
    dsd.StencilWriteMask = 0xFF;

    dsd.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
    dsd.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
    dsd.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
    dsd.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

    dsd.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
    dsd.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
    dsd.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
    dsd.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

    DXHRes(mDevice->CreateDepthStencilState(&dsd, &mDepthStencilState));
    mContext->OMSetDepthStencilState(mDepthStencilState, 1);

这是什么原因造成的,我应该查看哪个部分?

如有任何帮助,我们将不胜感激。

我解决了我的问题。我没有错误地设置任何设备资源(据我所知)。

对于遇到同样问题的其他人,我在每一帧都错误地设置了我的视图矩阵。确保正确设置相机视图矩阵(例如正确设置 XMMatrixLookAtLH')