Enable texture crash

Ok, here’s my new problem.

Everything renders fine , but as soon as I try to render a textured cube, I get a crash, the error is:

“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, NORMAL0”

I tried using a custom shader as well, but I get the same problem.
If I remove “effect.TextureEnabled = true”, everything is fine, except there is no texture rendered of course.

Anybody can help?

you need to supply TextureCoordinates in the VertexDecleration (UV) when creating the vertexbuffer

For example, if you currently use VertexPosition, you need to supply, VertexPositionTexture instead

If you are using a Model, you need to make sure, that it is exported with UV

Indeed you are correct in fact I tried that after posting this and it worked. I created a simple cube.obj manually with"vt" information and it was fine.

I wonder however, the error message seems to be a little misleading as it does not mention missing UV, rather , complains about positions and normals…oh well, the problem was resolved in the end.

it does not complain about position and Normals, it just tells you, that those elements were supplied - it’s unknown whats missing, because behind the scenes this is just a bunch of values with different strides and all it knows is, that the target-structure is a different size than the source-structure (at least I guess, that’s why)