I'm trying to get my code from calling each individual draw call down to using at least a VertexBuffer, and preferably an indexBuffer, but now that I'm attempting to test my code, I'm getting the error:

The current vertex declaration does not include all the elements required by the current vertex shader. Position0 is missing.

Which makes absolutely no sense to me, as my VertexDeclaration is:

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)

Which clearly contains the information. I am attempting to draw with the following lines:

VertexBuffer vb = new VertexBuffer(GraphicsDevice, VertexPositionColorNormal.VertexDeclaration, c.VertexList.Count, BufferUsage.WriteOnly);
IndexBuffer ib = new IndexBuffer(GraphicsDevice, typeof(int), c.IndexList.Count, BufferUsage.WriteOnly);


GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vb.VertexCount, 0, c.IndexList.Count/3);

Where c is a Chunk class containing an 8x8x8 array of boxes.

Full code is available at https://github.com/mrbaggins/Box/tree/ProperMeshing/box/box.

Relevant locations are Chunk.cs (Contains the VertexDeclaration) and Game1.cs (Draw() is in Lines 230-250). Not much else of relevance to this problem anywhere else. Note that large commented sections are from old version of drawing.

EDIT: I condensed the problem down even further, the following draw code won't even run, with the same error:

VertexBuffer vb = new VertexBuffer(GraphicsDevice, VertexPositionColor.VertexDeclaration, 3, BufferUsage.WriteOnly);
VertexPositionColor[] temp = {
            new VertexPositionColor(new Vector3(-3.0f,-3.0f,3.0f), Color.Blue),
            new VertexPositionColor(new Vector3(0.0f,0.0f,0.0f), Color.Blue),
            new VertexPositionColor(new Vector3(1.0f,1.0f,1.0f), Color.Blue) };

GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
  • \$\begingroup\$ I downloaded your project and it builds/runs for me. \$\endgroup\$ Nov 25, 2012 at 7:39
  • \$\begingroup\$ I downloaded too and its ok \$\endgroup\$
    – Blau
    Nov 25, 2012 at 9:16
  • \$\begingroup\$ Really? Are you getting a stripey box, or an XYZ marker? Because the XYZ marker is the current master branch, whereas the stripey box is the current branch (And the one I linked to)... \$\endgroup\$
    – Phil
    Nov 25, 2012 at 10:13
  • \$\begingroup\$ It was an XYZ marker with a tiny red square \$\endgroup\$ Nov 25, 2012 at 17:04
  • \$\begingroup\$ Ah, pretty sure that's the master branch, and I'm 99% sure a big brown/grey/green stripey box is the branch with the problems. If you have git, checkout propermeshing. \$\endgroup\$
    – Phil
    Nov 25, 2012 at 21:38

1 Answer 1


You need to tell the GraphicsDevice which IndexBuffer and VertexBuffer to use.

GraphicsDevice.Indices = ib;

Place those 2 lines before your draw call.

  • \$\begingroup\$ Well, that gets the program running again, which is nice. However: DrawIndexedPrimitives doesn't draw anything (I have other stuff drawing, which runs fine, but the boxes don't) DrawPrimitives draws some stuff, but because it's designed to be indexed it's all out of order and the boxes are a little out of whack / faces are wrong. \$\endgroup\$
    – Phil
    Nov 26, 2012 at 4:48
  • \$\begingroup\$ Update^ Nevermind, I had to uncomment the ib.setData<>. Now I have it drawing again, but every second triangle has it's normal backwards, which is odd because I explicitly set them. Will have to play with it. \$\endgroup\$
    – Phil
    Nov 26, 2012 at 5:03

You must log in to answer this question.

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