   mdx 2.0 Lighting problem
  Hi all,I'm using MDX 2.0 (yes I know it will never leave beta, but as I understand it XNA will run off the foundations of 2.0). I've just tried to convert the lights tutorial handed out in the usual SDK.However when the code runs no lights appear at all. Is there an extra call that needs to be made to get the lights to work in MDX 2.0Any help or pointers very much appreciated. CheersDRB2k2using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using Microsoft.DirectX;using Direct3D = Microsoft.DirectX.Direct3D;namespace ManagedLightsTutorial{    public partial class Form1 : Form    {   public Form1()   {  InitializeComponent();  this.InitializeGraphics();   }   // Our global variables for this project   Direct3D.Device device = null; // Our rendering device   Direct3D.VertexBuffer vertexBuffer = null;   Direct3D.PresentParameters presentParams = new Direct3D.PresentParameters();   bool pause = false;   public bool InitializeGraphics()   {  try  { presentParams.IsWindowed = true; // We don't want to run fullscreen presentParams.SwapEffect = Direct3D.SwapEffect.Discard; // Discard the frames  presentParams.EnableAutoDepthStencil = true; // Turn on a Depth stencil presentParams.AutoDepthStencilFormat = Direct3D.DepthFormat.D16; // And the stencil format device = new Microsoft.DirectX.Direct3D.Device(0, Direct3D.DeviceType.Hardware, this.Handle, Direct3D.CreateFlags.SoftwareVertexProcessing, this.presentParams); device.DeviceReset += new System.EventHandler(this.OnResetDevice); this.OnCreateDevice(device, null); this.OnResetDevice(device, null); pause = false; this.timer1.Tick += new EventHandler(timer1_Tick); this.timer1.Start(); return true;  }  catch (DirectXException p)  { // Catch any errors and return a failure System.Windows.Forms.MessageBox.Show(p.ToString()); return false;  }   }   void timer1_Tick(object sender, EventArgs e)   {  this.Render();   }   public void OnCreateDevice(object sender, EventArgs e)   {  Direct3D.Device dev = (Direct3D.Device)sender;  // Now Create the VB  vertexBuffer = Direct3D.VertexBuffer.CreateGeneric<Direct3D.CustomVertex.PositionNormal>(this.device, 100, Direct3D.Usage.WriteOnly, Direct3D.VertexFormats.PositionNormal, Direct3D.Pool.Default, new EventHandler(this.OnCreateVertexBuffer));   }   public void OnResetDevice(object sender, EventArgs e)   {  Direct3D.Device dev = (Direct3D.Device)sender;  // Turn off culling, so we see the front and back of the triangle  device.RenderState.CullMode = Direct3D.Cull.None;  // Turn on the ZBuffer  device.RenderState.ZBufferEnable = true;  device.RenderState.Lighting = true;    //make sure lighting is enabled   }   public void OnCreateVertexBuffer(object sender, EventArgs e)   {  Direct3D.VertexBuffer vb = (Direct3D.VertexBuffer)sender;  // Create a vertex buffer (100 customervertex)  Microsoft.DirectX.Generic.GraphicsBuffer<Direct3D.CustomVertex.PositionNormal> verts = vb.Lock<Direct3D.CustomVertex.PositionNormal>(0, 0, Direct3D.LockFlags.None); // Lock the buffer (which will return our structs)  for (int i = 0; i < 50; i++)  { // Fill up our structs float theta = (float)(2 * Math.PI * i) / 49; Direct3D.CustomVertex.PositionNormal p = new Microsoft.DirectX.Direct3D.CustomVertex.PositionNormal(); p.Position = new Vector3((float)Math.Sin(theta), -1, (float)Math.Cos(theta)); p.Normal = new Vector3((float)Math.Sin(theta), 0, (float)Math.Cos(theta)); Direct3D.CustomVertex.PositionNormal p1 = new Microsoft.DirectX.Direct3D.CustomVertex.PositionNormal(); p1.Position = new Vector3((float)Math.Sin(theta), 1, (float)Math.Cos(theta)); p1.Normal = new Vector3((float)Math.Sin(theta), 0, (float)Math.Cos(theta)); verts.Write(p); verts.Write(p1);  }  // Unlock (and copy) the data  vb.Unlock();   }   private void SetupMatrices()   {  // For our world matrix, we will just rotate the object about the y-axis.  device.Transform.World = Matrix.RotationAxis(new Vector3((float)Math.Cos(Environment.TickCount / 250.0f), 1, (float)Math.Sin(Environment.TickCount / 250.0f)), Environment.TickCount / 3000.0f);  // Set up our view matrix. A view matrix can be defined given an eye point,  // a point to lookat, and a direction for which way is up. Here, we set the  // eye five units back along the z-axis and up three units, look at the  // origin, and define "up" to be in the y-direction.  device.Transform.View = Matrix.LookAtLeftHanded(new Vector3(0.0f, 3.0f, -5.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));  // For the projection matrix, we set up a perspective transform (which  // transforms geometry from 3D view space to 2D viewport space, with  // a perspective divide making objects smaller in the distance). To build  // a perpsective transform, we need the field of view (1/4 pi is common),  // the aspect ratio, and the near and far clipping planes (which define at  // what distances geometry should be no longer be rendered).  device.Transform.Projection = Matrix.PerspectiveFieldOfViewLeftHanded((float)Math.PI / 4.0f, 1.0f, 1.0f, 100.0f);   }   private void SetupLights()   {  System.Drawing.Color col = System.Drawing.Color.White;  //Set up a material. The material here just has the diffuse and ambient  //colors set to yellow. Note that only one material can be used at a time.  Direct3D.Material mtrl = new Direct3D.Material();  mtrl.Diffuse = Color.White;// Microsoft.DirectX.ColorValue.FromColor(Color.White);  mtrl.Ambient = Color.White;//Microsoft.DirectX.ColorValue.FromColor(Color.White); ;  device.Material = mtrl;  //Set up a white, directional light, with an oscillating direction.  //Note that many lights may be active at a time (but each one slows down  //the rendering of our scene). However, here we are just using one. Also,  //we need to set the D3DRS_LIGHTING renderstate to enable lighting  device.Lights[0].LightType = Direct3D.LightType.Directional;  device.Lights[0].Diffuse = Color.White;// Microsoft.DirectX.ColorValue.FromColor(Color.White); ;  device.Lights[0].Direction = new Vector3((float)Math.Cos(Environment.TickCount / 250.0f), 1.0f, (float)Math.Sin(Environment.TickCount / 250.0f));  device.Lights[0].Enabled = true;//turn it on  device.Lights[0].Update();  //Finally, turn on some ambient light.  //Ambient light is light that scatters and lights all objects evenly  device.RenderState.Ambient = System.Drawing.Color.FromArgb(0x202020);   }   private void Render()   {  if (pause) return;  //Clear the backbuffer to a blue color   device.Clear(Direct3D.ClearFlags.Target | Direct3D.ClearFlags.ZBuffer, System.Drawing.Color.Blue, 1.0f, 0);  //Begin the scene  device.BeginScene();  // Setup the lights and materials  SetupLights();  // Setup the world, view, and projection matrices  SetupMatrices();  device.SetStreamSource(0, vertexBuffer, 0);  device.VertexFormat = Direct3D.CustomVertex.PositionNormal.Format;  device.DrawPrimitives(Direct3D.PrimitiveType.TriangleStrip, 0, (4 * 25) - 2);  //End the scene  device.EndScene();  // Update the screen  device.Present();   }   protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)   {  //this.Render(); // Render on painting   }   protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)   {  if ((int)(byte)e.KeyChar == (int)System.Windows.Forms.Keys.Escape) this.Close(); // Esc was pressed   }   protected override void OnResize(System.EventArgs e)   {  pause = ((this.WindowState == FormWindowState.Minimized) || !this.Visible);   }    }}