Original Post
I'm trying to get the lighting to work on my single triangle and I can't find out why its not working heres the code: any help would be greatly appreciated. [Edited by - Wicken on February 16, 2005 4:26:54 PM]
namespace game
{
public class Form1 : Form
{
D3D.Device device = null;
D3D.VertexBuffer vb = null;
protected D3D.CustomVertex.PositionNormalColored[] data;
public Form1()
{
InitD3D();
this.Size = new Size(800, 600);
this.Text = "GAME";
}
public void InitD3D()
{
D3D.PresentParameters param = new D3D.PresentParameters();
param.Windowed = true;
param.SwapEffect = D3D.SwapEffect.Discard;
param.AutoDepthStencilFormat = D3D.DepthFormat.D16;
data = new D3D.CustomVertex.PositionNormalColored[3];
device = new D3D.Device(0, D3D.DeviceType.Hardware, this, D3D.CreateFlags.SoftwareVertexProcessing, param);
this.Data();
//this.SetupMaterials();
this.Lights();
this.Camera();
}
public void Camera()
{
float angle = Environment.TickCount / 500.0F;
device.Transform.World = Matrix.RotationY(angle);
device.Transform.View = Matrix.LookAtLH(new Vector3(0, 0.5F, -3),
new Vector3(0, 0.5F, 0), new Vector3(0, 1, 0));
device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI/4.0F, 1.0F, 1.0F, 3.25F);
}
protected void SetupMaterials()
{
D3D.Material mat = new D3D.Material();
mat.Diffuse = Color.Blue;
mat.Specular = Color.LightGray;
mat.SpecularSharpness = 15.0F;
device.Material = mat;
device.RenderState.SpecularEnable = true;
}
public void Lights()
{
device.Lights[0].Diffuse = Color.White;
device.Lights[0].Type = D3D.LightType.Directional;
device.Lights[0].Direction = new Vector3(-1, -1, -3);
device.Lights[0].Update();
device.Lights[0].Enabled = true;
device.RenderState.Ambient = Color.White;
}
public void Data()
{
vb = new D3D.VertexBuffer(typeof(D3D.CustomVertex.PositionNormalColored), data.Length, device, D3D.Usage.WriteOnly, D3D.CustomVertex.PositionNormalColored.Format, D3D.Pool.Managed);
data[0] = new D3D.CustomVertex.PositionNormalColored(0, 1, 0, 0, 0, 1, Color.Purple.ToArgb());
data[1] = new D3D.CustomVertex.PositionNormalColored(-0.5f, 0, 0, 0, 0, 1, Color.Red.ToArgb());
data[2] = new D3D.CustomVertex.PositionNormalColored(0.5f, 0, 0, 0, 0, 1, Color.Green.ToArgb());
vb.SetData(data, 0, D3D.LockFlags.None);
}
public void Render()
{
device.VertexFormat = D3D.CustomVertex.PositionNormalColored.Format;
device.Clear(D3D.ClearFlags.Target, Color.Orange, 1.0f, 0);
//device.RenderState.Lighting = false;
device.RenderState.CullMode = D3D.Cull.None;
device.BeginScene();
this.Camera();
device.SetStreamSource(0, vb, 0);
device.DrawPrimitives(D3D.PrimitiveType.TriangleList, 0, 1);
device.EndScene();
device.Present();
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Return)
{
this.Close();
}
if (e.KeyChar == (char)Keys.Escape)
{
this.Close();
}
}
public static void Main()
{
Form1 form = new Form1();
form.Show();
while (form.Created)
{
form.Render();
Application.DoEvents();
}
}
}
}