0
\$\begingroup\$

I needed to create my own VertexElement with the follow - Position, Color & Normal. I found a tutorial explaining how to do this here (http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series1/Terrain_lighting.php).

I created a struct similar to the tutorial and then replaced all the declarations with the new one, but I get this error:

There is no boxing conversion from 'VertexPositionColorNormal' to 'Microsoft.Xna.Framework.Graphics.IVertexType'.

and I get it under the rendering line here:

graphicsDevice.DrawUserIndexedPrimitives<VertexPositionColorNormal>
(PrimitiveType.LineList, currentPlayer.LLObject.Vertices, 0, 
    currentPlayer.LLObject.TotalVertices, currentPlayer.LLObject.LinelistIndexes, 0, 
    currentPlayer.LLObject.TotalLinelistIndexes / 2);

I had a look on Google to see if there was any obvious answers but it's hard to search for. Could someone spread some light on what is going wrong?

\$\endgroup\$
2
\$\begingroup\$

That error indicates that XNA expect your custom vertex type to implement IVertexType as shown here. Otherwise you need to use the overload that accepts an explicit VertexDeclaration object.

\$\endgroup\$
  • \$\begingroup\$ This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. \$\endgroup\$ – Anko Aug 12 '13 at 23:54
  • 1
    \$\begingroup\$ I agree with @anko, this could have been a comment. But, you clearly knew the nature of the error message and hit it on the head. You should rephrase it to a statement and maybe add a bit of explanation. Your answer is correct, you might as well make it as high-quality as you can. \$\endgroup\$ – Seth Battin Aug 13 '13 at 4:19
  • \$\begingroup\$ Thanks I've improved the answer. I would have wrote that as a comment but I had less than 50 pts so I wasn't able to. \$\endgroup\$ – TheWanderer Aug 13 '13 at 9: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.