Original Post
I'm building a simple little game engine and a shooter on top of it to get my feet wet with XNA. The functionality of the 'effects' though are kind of throwing me. Permit me to drop some code on you ... I "make" my model; 2 squares for testing: I set up an effect object: And I try drawing: I always get 2 very flatly-colored polygons in the basicEffect.DiffuseColor color (green here). Setting VertexColorEnabled to true just turns everything black. Not sure what I'm fouling up here; thoughts?
vertices = new VertexPositionColor[12];
// top
vertices[0].Position = new Vector3(-20f, -20f, 20f);
vertices[0].Color = Color.Red;
vertices[1].Position = new Vector3(20f, -20f, 20f);
vertices[1].Color = Color.Red;
vertices[2].Position = new Vector3(-20f, 20f, 20f);
vertices[2].Color = Color.Red;
vertices[3].Position = new Vector3(20f, -20f, 20f);
vertices[3].Color = Color.Red;
vertices[4].Position = new Vector3(20f, 20f, 20f);
vertices[4].Color = Color.Red;
vertices[5].Position = new Vector3(-20f, 20f, 20f);
vertices[5].Color = Color.Red;
// bottom
vertices[6].Position = new Vector3(-20f, -20f, -20f);
vertices[6].Color = Color.Blue;
vertices[7].Position = new Vector3(20f, -20f, -20f);
vertices[7].Color = Color.Blue;
vertices[8].Position = new Vector3(-20f, 20f, -20f);
vertices[8].Color = Color.Blue;
vertices[9].Position = new Vector3(20f, -20f, -20f);
vertices[9].Color = Color.Blue;
vertices[10].Position = new Vector3(-20f, 20f, -20f);
vertices[10].Color = Color.Blue;
vertices[11].Position = new Vector3(20f, 20f, -20f);
vertices[11].Color = Color.Blue;
coloredVertexDeclaration = new VertexDeclaration(Game1.device, VertexPositionColor.VertexElements);
basicEffect = new BasicEffect(Game1.device, null);
basicEffect.Alpha = 1.0f;
basicEffect.DiffuseColor = new Vector3(0.1f, 0.9f, 0.1f);
basicEffect.SpecularColor = new Vector3(0.25f, 0.25f, 0.25f);
basicEffect.SpecularPower = 1.0f;
basicEffect.AmbientLightColor = new Vector3(0.75f, 0.75f, 0.75f);
basicEffect.DirectionalLight0.Enabled = true;
basicEffect.DirectionalLight0.DiffuseColor = Vector3.One;
basicEffect.DirectionalLight0.Direction = Vector3.Normalize(new Vector3(1.0f, -1.0f, -1.0f));
basicEffect.DirectionalLight0.SpecularColor = Vector3.One;
basicEffect.LightingEnabled = true;
basicEffect.World = Matrix.Identity;
basicEffect.View = Matrix.CreateLookAt(new Vector3(0, 0, 200), Vector3.Zero, Vector3.Up);
Matrix m = new Matrix();
Matrix.CreateOrthographic(800, 450, 0.1f, 1000, out m);
basicEffect.Projection = m;
basicEffect.Begin();
foreach (Powerup e in powerupList)
{
basicEffect.World *= Matrix.CreateTranslation(pos.X - camx, pos.Y - camy, 0f);
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Begin();
Game1.device.VertexDeclaration = coloredVertexDeclaration;
Game1.device.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 4);
pass.End();
}
}
basicEffect.End();