Drawing a 2D HUD messes up rendering of my 3D models?

前端 未结 1 1343
花落未央
花落未央 2021-01-24 07:59

I\'m using XNA 3.1

I have recently created a 2D Heads Up Display (HUD) by using Components.Add(myComponent) to my game. The HUD looks fine, showing a 2D map

相关标签:
1条回答
  • 2021-01-24 08:33

    You have to enable the depth buffer:

    // XNA 3.1
    GraphicsDevice.RenderState.DepthBufferEnable = true;
    GraphicsDevice.RenderState.DepthBufferWriteEnable = true;
    
    // XNA 4.0
    GraphicsDevice.DepthStencilState = DepthStencilState.Default;
    

    SpriteBatch.Begin alters the state of the graphics pipeline:

    • SpriteBatch render states for XNA 3.1
    • SpriteBatch render states for XNA 4.0

    In both versions depth buffering is disabled, that's what causes the issue.

    Again, I cannot stress this enough:

    Always make sure that ALL render states are correctly set before drawing any geometry.

    • BlendState
    • DepthStencilState
    • RasterizerState
    • Viewports
    • RenderTargets
    • Shaders
    • SamplerStates
    • Textures
    • Constants

    Educate yourself on the purpose of each state and each stage in the rendering pipeline. If in doubt, try resetting everything to default.

    0 讨论(0)
提交回复
热议问题