MonoGame:渲染3D模型和Spritebatch的问题

时间:2019-06-29 12:55:51

标签: c# 3d render monogame spritebatch

我想在屏幕上绘制一些调试信息,但这会导致渲染模型出现问题。我在互联网上找到了一些解决方案,但是没有用。也许我太傻了,但是我不知道怎么了。 这是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

1 个答案:

答案 0 :(得分:0)

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

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

GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;

如果给出相同的结果,请使用:

GraphicsDevice.RasterizerState = RasterizerState.CullClockwise;