Hey I’m having a little trouble. I’ve been working with xna for a while, but I’m completely new to 3D. I’m following the code verbatim from the winformsgraphicsdevice sample on the msdn website. It has a control that draws a primitive triangle to the screen. Simple as that, but I get an exception on this line:
GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1);
Which says:
"The current vertex declaration does not include all the elements required by the current vertex shader. Normal0 is missing."
I’m assuming it has something to do with my VertexPositionColor variable, vertices. That code is here:
vertices = new VertexPositionColor[3];
vertices[0] = new VertexPositionColor(new Vector3(-1, -1, 0), Color.Black);
vertices[1] = new VertexPositionColor(new Vector3( 1, -1, 0), Color.Black);
vertices[2] = new VertexPositionColor(new Vector3(0, 1, 0), Color.Black);
Your vertex shader is demanding a normal value (used for lighting calculations) but
VertexPositionColorstruct doesn’t have it.You’ll have to create a struct for storing vertex position, color AND normal data as it’s not a prebuilt type on XNA.
You can learn how to create it here: http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series1/Terrain_lighting.php
There he creates a struct called
VertexPositionColorNormal, use it instead ofVertexPositionColorthat you’re currently using.If you don’t want any lighting and you’re not using
BasicEffect, just remove your lighting variables/calculations from the technique you’re using.If you are using
BasicEffecttry settingLightingEnabledandTextureEnabledproperties to false.