1
\$\begingroup\$

I'm trying to draw 4 lines above map cells as cells access level using this code

VertexPositionColor[] collection = new VertexPositionColor[]
{
    new VertexPositionColor(new Vector3(loc.X + _cellPoints[0].X, loc.Y + _cellPoints[0].Y, 0f), color),
    new VertexPositionColor(new Vector3(loc.X + _cellPoints[0].X, loc.Y + _cellPoints[0].Y, 0f), color),

    new VertexPositionColor(new Vector3(loc.X + _cellPoints[1].X, loc.Y + _cellPoints[1].Y, 0f), color),
    new VertexPositionColor(new Vector3(loc.X + _cellPoints[1].X, loc.Y + _cellPoints[1].Y, 0f), color),


    new VertexPositionColor(new Vector3(loc.X + _cellPoints[2].X, loc.Y + _cellPoints[2].Y, 0f), color),
    new VertexPositionColor(new Vector3(loc.X + _cellPoints[2].X, loc.Y + _cellPoints[2].Y, 0f), color),

    new VertexPositionColor(new Vector3(loc.X + _cellPoints[3].X, loc.Y + _cellPoints[3].Y, 0f), color),
    new VertexPositionColor(new Vector3(loc.X + _cellPoints[3].X, loc.Y + _cellPoints[3].Y, 0f), color),

};

_vertexBuffer = new VertexBuffer(_device, VertexPositionColor.VertexDeclaration, 8, BufferUsage.WriteOnly);
_vertexBuffer.SetData(collection);

Device.SetVertexBuffer(_vertexBuffer);
Device.DrawPrimitives(PrimitiveType.LineList, 0, 4);

but it gives on this error

An error occurred while preparing to draw. This is probably because the current vertex declaration does not include all the elements required by the current vertex shader. The current vertex declaration includes these elements: SV_Position0, COLOR0.

in

Device.DrawPrimitives(PrimitiveType.LineList, 0, 4);
\$\endgroup\$
1
\$\begingroup\$

As the error says, the vertex declaration for the stream is missing some attributes required by the current vertex shader that's bound. Your code, and the error, indicate that you're filling a vertex buffer with "position" and "color" elements. But the shader you're using -- which you don't document here -- wants more.

Find where you are setting the active shader and change it so that the two agree: either swap the shader with one that only needs position and color, modify the existing shader so it only needs position and color, or determine what the extra data is and supply it in the vertex data.

\$\endgroup\$
  • \$\begingroup\$ As you noted here the shader isn't documented here. That might actually be the problem, if no shader is applied- this error will pop up. \$\endgroup\$ – Felsir Dec 8 '18 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.