【问题标题】:Writing text on screen affecting models在屏幕上书写影响模型的文本
【发布时间】:2014-01-01 02:29:43
【问题描述】:

我的游戏中有 3D 模型,但是当我通过 spritebatch 将文本添加到屏幕时,模型消失/变得透明。

我四处寻找解决方案,发现如果在绘制对象之前调用它应该可以工作

void prepare3d()
{
    GraphicsDevice.RenderState.DepthBufferEnable = true;
    GraphicsDevice.RenderState.AlphaBlendEnable = false;
    GraphicsDevice.RenderState.AlphaTestEnable = false;`

    GraphicsDevice.SamplerStates[0].AddressU = TextureAddressMode.Wrap;
    GraphicsDevice.SamplerStates[0].AddressV = TextureAddressMode.Wrap;
}

但是 RenderState 似乎不适用于 XNA 4.0。有人知道解决方法吗?

【问题讨论】:

    标签: c# graphics xna render


    【解决方案1】:

    对于 XNA 4.0,您可以尝试这样的方法:

    void prepare3d()
    {
        //set the depth buffer state
        DepthStencilState depthBufferState = new DepthStencilState();         
        depthBufferState.DepthBufferEnable = true; 
        GraphicsDevice.DepthStencilState = depthBufferState;
    
        //set the BlendState
        GraphicsDevice.BlendState = BlendState.Opaque;
        GraphicsDevice.DepthStencilState = DepthStencilState.Default;
    
        GraphicsDevice.SamplerStates[0].AddressU = TextureAddressMode.Wrap;
        GraphicsDevice.SamplerStates[0].AddressV = TextureAddressMode.Wrap;
    }
    

    这个Link 可能会有所帮助。

    HTH

    【讨论】:

      猜你喜欢
      • 2013-10-11
      • 2019-10-15
      • 1970-01-01
      • 2019-05-13
      • 1970-01-01
      • 2018-03-03
      • 1970-01-01
      • 1970-01-01
      • 2021-11-08
      相关资源
      最近更新 更多