DirectXTK and 3D Ojbect



我有一个使用D3D11和DirectXMath显示3D对象的应用程序。我还想在左上角显示一个HUD,所以我想我会使用DirectXTK sprintBatch/spriteFont来做到这一点。我的3D是好的,直到我添加以下代码。DirectXTK使用它自己的着色器和改变一些状态?

问题是我如何解决这个问题?

m_spriteBatch->Begin();
        const wchar_t* output = L"Hello World";
        m_font->DrawString(m_spriteBatch.get(), output, DirectX::XMFLOAT2{ 10, 10 }, Colors::Yellow);
        m_spriteBatch->End();

没有spritefont ->细绳

spritefont ->细绳

这是我的着色器。

Texture2D txDiffuse : register( t0 );
SamplerState samLinear : register(s0);
cbuffer WorldViewProjectionType : register(b0)
{
    matrix World;
    matrix View;
    matrix Projection;
};
cbuffer TransparentBuffer
{
    float4 blendAmount;
};
struct VS_INPUT
{
    float4 Pos : POSITION;
    float2 Tex : TEXCOORD0;
};
struct PS_INPUT
{
    float4 Pos : SV_POSITION;
    float2 Tex : TEXCOORD0;
};
PS_INPUT VS(VS_INPUT input)
{
    PS_INPUT output = (PS_INPUT)0;
    output.Pos.w = 1.0f;
    output.Pos = mul(input.Pos, World);
    output.Pos = mul(output.Pos, View);
    output.Pos = mul(output.Pos, Projection);
    output.Tex = input.Tex;
    return output;
}
float4 PS(PS_INPUT input) : SV_Target
{
    float4 color = txDiffuse.Sample(samLinear, input.Tex);
    color.a = blendAmount.a;
    return color;
}
float4 PSGray(PS_INPUT input) : SV_Target
{
    float4 color = txDiffuse.Sample(samLinear, input.Tex);
    float fLuminance = 0.299f * color.r + 0.587f * color.g + 0.114f *          color.b;
    return float4(fLuminance, fLuminance, fLuminance, blendAmount.a);
}

太好了,我搞定了。yippy。在swapchain->present之后,我重置了所有这些

            //*************************************************************************
        m_pImmediateContext->IASetInputLayout(m_pVertexLayout);
        m_pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
        TurnOffAlphaBlending(m_pImmediateContext);
        // Set the depth stencil state.
        m_pImmediateContext->OMSetDepthStencilState(m_pdepthStencilState, 1);
        m_pImmediateContext->OMSetRenderTargets(1, &m_pdesignerRenderTargetView, m_pdesignerDepthStencilView);
        m_pImmediateContext->RSSetState(m_prasterState);
        //*************************************************************************

相关内容

  • 没有找到相关文章

最新更新