This is a great tutorial. I just got visual C# express. Was using VC++ 6 before this. Wow, i was so behind the times. Finally i think i'll be able to learn directX. So anyways, ive been playing with the tutorial code and thought i'd share my findings (as
i understand them so far).
The tutorial uses PositionColored vectors which specify a location in World Space. And it's rendering them using the gfxdevice.DrawUserPrimitives method which doesn't use the vectorBuffer. The alternative method is to use gfxdevice.DrawPrimitives, which assumes you ARE using the vectorBuffer and you've already loaded the primitive into the buffer. I'm guessing there are situations where it's difficult to use the buffering method and rendering your primitives straight from system memory is more flexible.
A TransformedColored vector specifies a location in Screen Space. And when such a primitive is rendered, viola, it's flat on the screen. So there's the first step to a 2D vector application. I've presented the code below to initialize the vertexBuffer with a TransformedColored primitive and render it to the screen. You'll notice that im using an alternate method of creating vertices, instead of creating the Position and Color separately, they can be created together. I dont know why a Vector4 is required (and its z, w values).
I hope this code works for you, i'm just learning, so i may have left something out. Let me know how it goes.
// BEGIN CODE
this.InitializeVertexBuffer(); // initialize 2d primitive
protected void Draw2dScene()
gfxdevice.SetStreamSource(0, vertexBuffer, 0);
gfxdevice.VertexFormat = CustomVertex.TransformedColored.Format;
gfxdevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
public void InitializeVertexBuffer()
CustomVertex.TransformedColored verts = new CustomVertex.TransformedColored;
verts = new CustomVertex.TransformedColored(new Vector4(150, 50, 1, 1), Color.Red.ToArgb());
verts = new CustomVertex.TransformedColored(new Vector4(250, 250, 1, 1), Color.Blue.ToArgb());
verts = new CustomVertex.TransformedColored(new Vector4(50, 250, 1, 1), Color.Green.ToArgb());
vertexBuffer = new VertexBuffer(typeof(CustomVertex.TransformedColored), verts.Length,
gfxdevice, 0, CustomVertex.TransformedColored.Format, Pool.Default);
GraphicsStream graphicsStream = vertexBuffer.Lock(0, 0, LockFlags.None);
// END CODE
This is a great tutorial. I just got visual C# express. Was using VC++ 6 before this. Wow, i was so behind the times. Finally i think i'll be able to learn directX. So anyways, ive been playing with the tutorial code and thought i'd share my findings (as i understand them so far).