DirectX 9 & c# problem
-
I didn't see a DirectX board so I thought I'd post here since I am writing in C#. I am having an issue with setting some vectors on a CustomVertex. Here is my code:
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI/4, this.Width/this.Height, 1f, 50f); device.Transform.View = Matrix.LookAtLH(new Vector3(0,0,30), new Vector3(0,0,0), new Vector3(0,1,0)); device.RenderState.Lighting = false; device.RenderState.CullMode = Cull.None; CustomVertex.PositionColored[] vertices = new CustomVertex.PositionColored[3]; vertices[0].SetPosition(new Vector3(0f, 0f, 0f)); vertices[0].Color = Color.Red.ToArgb(); vertices[1].SetPosition(new Vector3(10f, 0f, 0f)); vertices[1].Color = Color.Green.ToArgb(); vertices[2].SetPosition(new Vector3(5f, 100f, 0f)); vertices[2].Color = Color.Yellow.ToArgb(); device.Clear(ClearFlags.Target, Color.DarkSlateBlue, 1.0f, 0); device.BeginScene(); device.VertexFormat = CustomVertex.PositionColored.Format; device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices); device.EndScene(); device.Present(); this.Invalidate(); }
The problem is with the vertices[x].SetPosition(new Vector3(0f, 0f, 0f)); When I try to compile, I get the error message: Microsoft.DirectX.Direct3D.CustomVertex.PositionColored does not contain a definition for SetPosition. I have also tried: vertices[x].Position.Add(new Vector3(0f, 0f, 0f)); This doesn't give me an error, but it also doesn't render anything on the screen. Also, I can render the triangle if I use CustomVertex.TransformedColored so I know that is working, but I need to use CustomVertex.PositionColored In most of the examples I have seen, this is how it is done. If you know DirectX, then you also know it is very hard to find any sort of good documentation on it too. I don't know if most examples I am following are 8.0 and earlier. Is there another way to do this? Am I doing it right but missing something?