I am trying to render G-Code generated for a 3d-printer as the printed product by reading the file as line segments and the drawing cylinders with the diameter of the filament around the segment. I think I have managed to do this part right because the vertex I am sending to the graphics device appear to have been processed correctly. My problem I think lies somewhere in the rendering. What basically happens is that when I start rotating my model in the X or Y axis then it renders perfectly for half of the rotation but then for the other half it has this weird effect where you start seeing through the outer filament into some of the shapes inside. This effect is the strongest with X rotations though.

Here is a picture of the part of the rotation that looks correct:

enter image description here

And here is one that looks horrible:

enter image description here

I am still quite new to XNA and/Monogame and 3d programming as a whole. I have no idea what could possibly be causing this and even less of an idea of what this type of behavior is called. I am guessing this has something to do with rendering so have added the code for that part:

    protected override void Draw(GameTime gameTime)

        basicEffect.World = world;
        basicEffect.View = view;
        basicEffect.Projection = projection;
        basicEffect.VertexColorEnabled = true;


        RasterizerState rasterizerState = new RasterizerState();
        rasterizerState.CullMode = CullMode.CullClockwiseFace;
        rasterizerState.ScissorTestEnable = true;
        GraphicsDevice.RasterizerState = rasterizerState;

        foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
            GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, vertexBuffer.VertexCount);


I don't know if it could be because I am shading something that does not really have a texture. I am using this custom vertex declaration I found on some tutorial that allows me to store a vertex with a position, color and normal:

    public struct VertexPositionColorNormal
        public Vector3 Position;
        public Color Color;
        public Vector3 Normal;

        public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration
            new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
            new VertexElement(sizeof(float) * 3, VertexElementFormat.Color, VertexElementUsage.Color, 0),
            new VertexElement(sizeof(float) * 3 + 4, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0)

If any of you have ever seen this type of thing please help. Also, if you think that the problem might lay somewhere else in my code then please just request what part you would like to see in the comments section.

  • \$\begingroup\$ try rasterizerState.CullMode = CullMode.CullCounterClockwise; (which is default) and also GraphicsDevice.DepthStencilState = DepthStencilState.Default; \$\endgroup\$
    – user9790
    Jun 2, 2013 at 8:19
  • \$\begingroup\$ Thanks, this helps a lot but the effect is still very much there. It does appear though that the amount it can rotate before becoming completely messed up has increased. \$\endgroup\$
    – Gerharddc
    Jun 2, 2013 at 8:26
  • \$\begingroup\$ Do you use a SpriteBatch at all by any chance? It changes a lot of properties that can cause some damage. \$\endgroup\$ Jun 3, 2013 at 1:50

1 Answer 1


Looks to me like a lack of a depth buffer, so that the cylinders are being drawn on top of each other in the order you supply them, rather than according to their depth on screen.

I don't know XNA so I can't advise you as to specific programming, but make sure that when you create/request your context (GraphicsDevice?) you request that it has a depth buffer.

  • 2
    \$\begingroup\$ And of course, enable depth testing. \$\endgroup\$ Aug 2, 2013 at 6:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .