Hey guys,
I've just started going through the DirectX 9.0c (SDK Summer 2004) tutorials, and I've got them working without a hitch. Only problem is, there's a couple of things I don't fully understand and I was wondering if someone could give me a quick description.
I'm on the second tutorial which deals primarily with vertex buffers. Here's the relevant code.
public void OnCreateVertexBuffer(object sender, EventArgs e)
{
VertexBuffer vb = (VertexBuffer) sender;
GraphicsStream stm = vb.Lock(0, 0, 0);
CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[3];
verts[0].X = 150; verts[0].Y = 50; verts[0].Z = 0.5f; verts[0].Rhw = 1; verts[0].Color = System.Drawing.Color.Aqua.ToArgb();
verts[1].X = 250; verts[1].Y = 250; verts[1].Z = 0.5f; verts[1].Rhw = 1; verts[1].Color = System.Drawing.Color.Brown.ToArgb();
verts[2].X = 50; verts[2].Y = 250; verts[2].Z = 0.5f; verts[2].Rhw = 1; verts[2].Color = System.Drawing.Color.LightPink.ToArgb();
stm.Write(verts);
vb.Unlock();
}
I understand what is happening in regards to the verts[] array being setup, but I'm not really understanding the use of vb.Lock() and vb.Unlock(). Is there a reason that vb.Lock() is called to initialise the GraphicsStream? The reason I ask is because after taking a look at the VertexBuffer class, it looks as though I could just call:
vb.SetData(verts, 0, LockFlags.None);
Would this accomplish the same thing?
Thanks in advance.