Vertex Buffer problems with C# DX9

Started by
1 comment, last by Wicken 19 years, 2 months ago
I have been trying for quite some time now to get this vertex buffer to work. All im trying to do is do is draw a single triangle, it worked without the Vertex Buffer but with it it just doesn't draw it. Heres my code: using System; using System.Drawing; using System.Data; using System.Diagnostics; using System.Windows.Forms; using Microsoft.DirectX; using D3D = Microsoft.DirectX.Direct3D; namespace game { public class Form1 : Form { D3D.Device device = null; D3D.VertexBuffer vb = null; protected D3D.CustomVertex.TransformedColored[] 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; data = new D3D.CustomVertex.TransformedColored[3]; device = new D3D.Device(0, D3D.DeviceType.Hardware, this, D3D.CreateFlags.SoftwareVertexProcessing, param); vb = new D3D.VertexBuffer(typeof(D3D.CustomVertex.TransformedColored), data.Length, device, D3D.Usage.WriteOnly, D3D.CustomVertex.TransformedColored.Format, D3D.Pool.Managed); data[0].X = 800.0f; data[0].Y = 0.0f; data[0].Z = 1.0f; data[0].Rhw = 1.0f; data[0].Color = Color.Red.ToArgb(); data[1].X = 800.0f; data[1].Y = 600.0f; data[1].Z = 1.0f; data[1].Rhw = 1.0f; data[1].Color = Color.Red.ToArgb(); data[2].X = 0.0f; data[2].Y = 600.0f; data[2].Z = 1.0f; data[2].Rhw = 1.0f; data[2].Color = Color.Red.ToArgb(); vb.SetData(data, 0, D3D.LockFlags.None); } public void Render() { device.VertexFormat = D3D.CustomVertex.TransformedColored.Format; device.Clear(D3D.ClearFlags.Target, Color.Black, 1.0f, 0); device.BeginScene(); device.SetStreamSource(0, vb, 0); device.DrawUserPrimitives(D3D.PrimitiveType.TriangleStrip, 0, data.Length / 3); device.EndScene(); device.Present(); } public static void Main() { Form1 form = new Form1(); form.Show(); while (form.Created) { form.Render(); Application.DoEvents(); } } } } If anyone could help me it would be very appreciated, thank you. Oh, and sorry for the messy code.
Advertisement
Change your DrawUserPrimitives() to DrawPrimitives(). Should work.

Co-creator of Star Bandits -- a graphical Science Fiction multiplayer online game, in the style of "Trade Wars'.
Wow, cant believe I missed that. Thanks alot.

This topic is closed to new replies.

Advertisement