0

I want to draw some debug info on screen, but this cause problem with rendering model. I found some solutions in the internet, but it dosen't work. Maybe i'm too stupid, but i don't know what's wrong. Here's Draw method:

    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

  • Possible duplicate of [Drawing a 2D HUD messes up rendering of my 3D models?](https://stackoverflow.com/questions/14938832/drawing-a-2d-hud-messes-up-rendering-of-my-3d-models) –  Jun 30 '19 at 16:16
  • As you can see, i reset depth buffer, so this isn't the problem. There is something else, but i can't get what. – CyberDragonTech Jun 30 '19 at 17:16
  • What is the issue with output? –  Jun 30 '19 at 18:29
  • I added image to description. I don't know why it's happaen. I used brakepoint to check values of GraphicsDevice, but i didn't find changes at moment of drawing 3d model. – CyberDragonTech Jul 01 '19 at 06:29

1 Answers1

0

The Triangles normals (the forward face) are being drawn backwards. This is defined by the order of the vertices in the vertexbuffer.

Luckily, we can specify the order in the GraphicsDevice. Just add the line:

GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;

If that gives the same result use:

GraphicsDevice.RasterizerState = RasterizerState.CullClockwise;
  • Thanks. It helps. Plus before i created model with setting verteces itself, but now i created model and with GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; it render correctly. – CyberDragonTech Jul 02 '19 at 06:04
  • Just to be clear, that was the third line of the things to check under the linked post. I am glad it helped. –  Jul 02 '19 at 06:07