I'm stumped with this error 'The current vertex declaration does not include all the elements required by the current vertex shader. Normal0 is missing. It is occuring on this line: graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, gridVertices, 0, 6);
I've started a projet from scratch to try narrow down where I'm going wrong but no luck.
Basically what I'm trying to do is setup a 'grid'. (All points are calculated in the SetupGrid method). All the calculated vertices seem fine coordinate wise. Here's a copy of them either way:
- + [0] {Position:{X:-10 Y:0.5 Z:-10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
+ [1] {Position:{X:-10 Y:0.5 Z:10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
+ [2] {Position:{X:-5 Y:0.5 Z:-10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
+ [3] {Position:{X:-5 Y:0.5 Z:10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
+ [4] {Position:{X:0 Y:0.5 Z:-10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
+ [5] {Position:{X:0 Y:0.5 Z:10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
+ [6] {Position:{X:5 Y:0.5 Z:-10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
+ [7] {Position:{X:5 Y:0.5 Z:10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
+ [8] {Position:{X:10 Y:0.5 Z:-10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
+ [9] {Position:{X:10 Y:0.5 Z:10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
+ [10] {Position:{X:-10 Y:0.5 Z:-10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
+ [11] {Position:{X:10 Y:0.5 Z:-10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
+ [12] {Position:{X:-10 Y:0.5 Z:-5} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
+ [13] {Position:{X:10 Y:0.5 Z:-5} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
+ [14] {Position:{X:-10 Y:0.5 Z:0} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
+ [15] {Position:{X:10 Y:0.5 Z:0} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
+ [16] {Position:{X:-10 Y:0.5 Z:5} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
+ [17] {Position:{X:10 Y:0.5 Z:5} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
+ [18] {Position:{X:-10 Y:0.5 Z:10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
+ [19] {Position:{X:10 Y:0.5 Z:10} Color:{R:255 G:0 B:0 A:255}} Microsoft.Xna.Framework.Graphics.VertexPositionColor
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace DelXnaGrideLine
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
BasicEffect effect;
VertexPositionColor[] gridVertices;
int gridLineCount;
private void SetupGrid(int width, int height, int lineCount, float yHeight, Color color)
{
gridLineCount = lineCount * 2;
gridVertices = new VertexPositionColor[lineCount * 4];
int xDiff = width / (lineCount - 1);
int zDiff = height / (lineCount - 1);
int xStart = -width / 2;
int xEnd = width / 2;
int zStart = -height / 2;
int zEnd = height / 2;
for (int x = 0; x < lineCount; x++)
{
gridVertices[x * 2] = new VertexPositionColor(
new Vector3(xStart + (x * xDiff), yHeight, zStart),
color);
gridVertices[x * 2 + 1] = new VertexPositionColor(
new Vector3(xStart + (x * xDiff), yHeight, zEnd),
color);
}
int halfLine = lineCount * 2;
for (int z = 0; z < lineCount; z++)
{
gridVertices[halfLine + z * 2] = new VertexPositionColor(
new Vector3(xStart, yHeight, zStart + (z * xDiff)),
color);
gridVertices[halfLine + z * 2 + 1] = new VertexPositionColor(
new Vector3(xEnd, yHeight, zStart + (z * xDiff)),
color);
bool bob = true;
}
}
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
effect = new BasicEffect(GraphicsDevice);
effect.VertexColorEnabled = true;
effect.LightingEnabled = true;
SetupGrid(20, 20, 5, 0.5f, Color.Red);
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
float aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;
Vector3 cameraPosition = new Vector3(1, 12, 3);
Vector3 cameraView = new Vector3(0.5f, 0.5f, 0.5f);
effect.View = Matrix.CreateLookAt(cameraPosition, cameraView, Vector3.Up);
effect.Projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 1000.0f);
effect.World = Matrix.Identity;
effect.CurrentTechnique.Passes[0].Apply();
graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(
PrimitiveType.LineList, gridVertices, 0, 6);
base.Draw(gameTime);
}
}
}

Find content
Not Telling