# Why does my VertexDeclaration apparently not contain Position0?

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);

vb.SetData<VertexPositionColorNormal>(c.VertexList.ToArray());
ib.SetData<int>(c.IndexList.ToArray());

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) };

vb.SetData<VertexPositionColor>(temp);
GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);

• I downloaded too and its ok – Blau Nov 25 '12 at 9:16
• 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)... – Phil Nov 25 '12 at 10:13
• It was an XYZ marker with a tiny red square – Luis Estrada Nov 25 '12 at 17:04
• 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. – Phil Nov 25 '12 at 21:38

GraphicsDevice.Indices = ib;