簡體   English   中英

MonoGame:渲染3D模型和Spritebatch的問題

[英]MonoGame: problem with rendering 3d model and 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);
    }

這里看起來像

三角形法線(正面)向后繪制。 這由頂點緩沖區中頂點的順序定義。

幸運的是,我們可以在GraphicsDevice指定順序。 只需添加以下行:

GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;

如果給出相同的結果,請使用:

GraphicsDevice.RasterizerState = RasterizerState.CullClockwise;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM