1
\$\begingroup\$

I seem to be having trouble with rendering models in monogame. I'm trying to draw several cubes, in a minecraft style world. It's a simple .obj file, nothing special. But... for whatever reason, both the top and the bottom are rendering over the sides, as can be seen here in these four cubes.

here's the problem

My code is simple as can be, so I can't imagine the problem is directly the fault of this:

public static void DrawModel(Model model, Matrix modelspace, Texture2D texture)
    {

        foreach (ModelMesh mesh in model.Meshes)
        {
            foreach (BasicEffect effect in mesh.Effects)
            {

                //effect.EnableDefaultLighting();
                effect.TextureEnabled = true;
                effect.Texture = texture;
                effect.World = modelspace;
                effect.View = Cameraworks.ActiveCamera.View;
                effect.Projection = Cameraworks.ActiveCamera.Projection;
            }

            mesh.Draw();
        }

    }

How do I fix this?

\$\endgroup\$
  • 1
    \$\begingroup\$ Looks like some of your normals are inverted... Check in your 3D editor to make sure they're pointing outward. \$\endgroup\$ – Vaillancourt Jul 7 '16 at 10:48
  • \$\begingroup\$ Normals inverted, like @AlexandreVaillancourt said, or somehow your meshes are going ACB instead of ABC (vertex direction). \$\endgroup\$ – Jesse Williams Jul 7 '16 at 16:08
  • \$\begingroup\$ Any clue would I go about fixing the latter problem? How would I make them go in the correct order... \$\endgroup\$ – Charybdizs Jul 7 '16 at 16:54
0
\$\begingroup\$

It turns out, it was because of a previous SpriteBatch call causing the GraphicsDevice settings to be changed. Putting this code in before my model drawing code executed fixed it, and now it draws correctly.

GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.