I'm trying to learn how to use VertexBuffers in XNA 4.0. I can render wireframe shapes and I can render textured shapes. However, I'm having some trouble rendering them both at once. I'm initializing the buffers like this:

vertexBuffer1 = new VertexBuffer(graphics.GraphicsDevice, vertexDeclarationWireframe, numPointsWireframe, BufferUsage.None);

vertexBuffer3 = new VertexBuffer(graphics.GraphicsDevice, vertexDeclarationTexture, numPointsTexture, BufferUsage.None);

The above code fails during Draw() because the vertex buffers are using two different types of vertexDeclarations, one for wireframe (VertexPositionColor) and one for textures (VertexPositionTexture). I tried moving the call to VertexBuffer.SetData() to just before the relevant geometry is drawn but that didn't work.

I've also tried setting my Effect object TextureEnabled = false when wireframe is being rendered and resetting it when the textured geometry is rendering, but that didn't work either. The effect seems to be expecting a TextureCoordinate regardless.

What's the proper way to do this?

  • 4
    \$\begingroup\$ Show us your rendering code, including where you use SetVertexBuffer and DrawPrimitives (or similar). \$\endgroup\$ Aug 4, 2011 at 0:47

1 Answer 1


All you need to do is set a new RasterizerState object on your GraphicsDevice that specifies wireframe (or not). Specifically to accomplish what you're trying to do here are the steps:

  1. Draw your vertex buffer with depth & depth write enabled and filled shading
  2. On your GraphicsDevice object set a new RasterizerState that specifies wireframe and a new DepthStencilState that disables both depth testing and depth writing
  3. Draw the same vertex buffer again but use a different effect. For example when you draw the wireframe mesh only output a constant color or maybe just vertex colors. If you don't change the Effect being used then the wireframe mesh won't show up because it'll be the same color as the original.

This is all accomplished with only 1 vertex buffer.

  • \$\begingroup\$ An alternative is to set the FillMode value directly in the shader's technique declaration. Cleaner in some circumstances and doesn't require creating new rasterizer state object. \$\endgroup\$
    – 3Dave
    Sep 5, 2011 at 15:14
  • \$\begingroup\$ in the technique delcaration you can set the fillmode to wireframe and DepthBias value to a small negative value too. \$\endgroup\$
    – Blau
    Oct 4, 2011 at 16:18

You must log in to answer this question.

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