Vertex Buffer problem with C# DX9
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.
[Edited by - Wicken on February 15, 2005 3:42:23 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement