I'm trying to create a voxel game using XNA, but I'm getting a somewhat bizarre error when calling DrawIndexedPrimitives()
:
InvalidOperationException was unhandled
The current vertex declaration does not include all the elements required by the
current vertex shader. TextureCoordinate0 is missing.
Which makes some sense, as it's true my vertex data structure (VertexPositionColorNormal
as shown in this Riemers tutorial) does not contain texture data.
However, the effect shouldn't require texture data - I made it a point to set drawingEngine.TextureEnabled = false;
in my graphics setup method. So why is this exception being thrown? And what can I do about it?
For some context, here's my draw method:
public void Draw(SpriteBatch drawer)
{
drawingEngine.View = player.createViewMatrix();
Vector3 direction = player.getDirection();
for (int x = 0; x < mapSize; x++)
{
for (int z = 0; z < mapSize; z++)
{
Chunk drawee = map.get(new IntVector3(x, mapCenter, z));
if (drawee == null)
continue;
if(drawee.isTransparent())
continue;
#region chunkdrawer
DynamicVertexBuffer vertexBuffer = drawee.getVertexBuffer();
int numVertices = drawee.getNumVertices();
DynamicIndexBuffer indexBuffer = drawee.getIndexBuffer();
int numIndices = drawee.getNumIndices();
graphics.SetVertexBuffer(vertexBuffer);
graphics.Indices = indexBuffer;
foreach (EffectPass p in drawingEngine.CurrentTechnique.Passes) //Not sure I entirely understand this
{
graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, numVertices, 0, numIndices / 3);
}
#endregion chunkdrawer
}
}
drawer.End();
drawer.Begin();
}
And here is the graphics setup method:
void graphicsNonsense()
{
drawingEngine = new BasicEffect(graphics);
drawingEngine.World = world;
drawingEngine.Projection = projection;
drawingEngine.TextureEnabled = false;
drawingEngine.VertexColorEnabled = true;
drawingEngine.EnableDefaultLighting();
drawingEngine.SpecularColor= new Vector3(0, 0, 0);
}