【问题标题】:MonoGame: problem with rendering 3d model and spritebatchMonoGame:渲染 3d 模型和 spritebatch 的问题
【发布时间】:2019-11-11 01:12:19
【问题描述】:

我想在屏幕上绘制一些调试信息,但这会导致渲染模型出现问题。我在互联网上找到了一些解决方案,但它不起作用。也许我太笨了,但我不知道怎么了。 这是Draw方法:

    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.DarkCyan);

        spriteBatch.Begin();
        player.Draw(dt);
        spriteBatch.DrawString(gamefont, "render Time :" + gameTime.ElapsedGameTime.TotalSeconds, new Vector2(0, 85), Color.White);
        spriteBatch.End();

        effect.View = player.view;
        effect.Projection = player.projection;
        effect.Texture = dirtTexture;

        GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;
        GraphicsDevice.BlendState = BlendState.Opaque;
        GraphicsDevice.DepthStencilState = DepthStencilState.Default;

        foreach (EffectPass p in effect.CurrentTechnique.Passes)
        {
            p.Apply();
            effect.World = player.world;
            GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, buffer.VertexCount / 3);
        }



        base.Draw(gameTime);
    }

Here how it look like

【问题讨论】:

  • 如您所见,我重置了深度缓冲区,所以这不是问题。还有其他东西,但我无法得到什么。
  • 输出有什么问题?
  • 我在描述中添加了图片。我不知道为什么会这样。我使用了刹车点来检查 GraphicsDevice 的值,但在绘制 3d 模型时我没有发现变化。

标签: c# 3d render monogame spritebatch


【解决方案1】:

三角形法线(前面)被向后绘制。这是由顶点缓冲区中顶点的顺序定义的。

幸运的是,我们可以在GraphicsDevice 中指定顺序。只需添加以下行:

GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;

如果结果相同,请使用:

GraphicsDevice.RasterizerState = RasterizerState.CullClockwise;

【讨论】:

  • 谢谢。它有助于。加上在我创建模型之前设置顶点本身,但现在我创建模型并使用 GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;它呈现正确。
  • 为了清楚起见,这是链接帖子下要检查的第三行。我很高兴它有所帮助。
猜你喜欢
  • 1970-01-01
  • 2016-09-10
  • 1970-01-01
  • 2021-08-16
  • 2014-01-22
  • 1970-01-01
  • 2019-03-04
  • 2017-08-05
  • 2013-03-25
相关资源
最近更新 更多