1
\$\begingroup\$

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);
}
\$\endgroup\$
3
  • \$\begingroup\$ Try to enable VertexColors in the drawingEngine structure like you disabled textures, see if it helps. \$\endgroup\$ Nov 30, 2014 at 8:55
  • \$\begingroup\$ Yeah, I did that, no change :( \$\endgroup\$ Nov 30, 2014 at 10:00
  • \$\begingroup\$ It's probably worth noting that I also tried putting those two statements into the foreach effectpass loop, which also yielded no change. \$\endgroup\$ Nov 30, 2014 at 10:49

1 Answer 1

1
\$\begingroup\$

Try calling p.Apply() in your drawing code to set the effect correctly on the GPU before drawing.

foreach (EffectPass p in drawingEngine.CurrentTechnique.Passes)
{
    p.Apply(); // this will set the effect
    graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, numVertices, 0, numIndices / 3);
}
\$\endgroup\$
0

You must log in to answer this question.

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