In my 2D XNA game, I've been trying to draw triangles. I've been following the tutorial here.
// Game1.FX is a static instance of Effect
Game1.FX.CurrentTechnique = Game1.FX.Techniques["Pretransformed"];
foreach (EffectPass pass in Game1.FX.CurrentTechnique.Passes)
{
pass.Apply();
Game1.GameInstance.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1, VertexPositionColor.VertexDeclaration);
}
// Exception is thrown when we go back to spriteBatch.Draw()
spriteBatch.Draw(Textures.Get("Projectiles\\laser01"), new Rectangle((int)compartment.Position.X, (int)compartment.Position.Y,
compartment.CompartmentWeapon.MaxRange, 2), null, laserColour, gunRotation - compartment.CompartmentWeapon.ArcLOS, Vector2.Zero, SpriteEffects.None, 1);
I receive a System.InvalidOperationException when going back to the spriteBatch.Draw() from the GraphicsDevice.DrawUserPrimitives().
"A valid vertex buffer (and a valid index buffer if you are using indexed primitives) must be set on the device before any draw operations may be performed."
I would be grateful if anyone could point out why this is happening.