Attributes of Vertices: (Note, the plural of vertex is vertices, not vertexes)

Of course, a VertexBuffer holds a bunch of these vertices.

'Next, our vertex buffer. 'I don't use overload #1 or #3 because I don't know how big a TransformedColored vertex is. VxB = New VertexBuffer(GetType(CustomVertex.TransformedColored), 5, D9, Usage.WriteOnly, CustomVertex.TransformedColored.Format, Pool.Managed) 'That is a LOT of non-trivial parameters. |

'After that workout, we now have to actually set the vertices. 'We do this by locking the surface out of D9 while we "operate" on it. Dim A As Array = VxB.Lock(0, LockFlags.None) 'It returns a vanilla array... Vertices = DirectCast(A, CustomVertex.TransformedColored()) 'So we have to convert it to an array of TransformedColored vertices. |

'Note that it will return an array of 3 because that's how many we specified in the vertex buffer constructor. Vertices(0) = New CustomVertex.TransformedColored(200.0F, 150.0F, 0.0F, 1.0F, &HC0C0C0) 'X,Y,Z,RHW, and color. 'X and Y are self-explanatory at the moment: they are the coordinates of the vertex on the form. 'I just set Z to 0. 'RHW: Regularly Holds (W)one... yeah, it really stands for "Reciprocal of Homogenous W"... what's W? 'A coefficient in some mathematical operation, probably. 'Color is in the &HRRGGBB format: the first two hex digits control the blue in the color, 3 and 4 control the green, and '5 and 6 control the red. Of course, you can always use Color.ToArgb() to get a color. 'I figure I can do all of this inline since I'm just setting values for the vertices. Vertices(1).X = 200.0F : Vertices(1).Y = 250.0F : Vertices(1).Rhw = 1.0F : Vertices(1).Color = &HFF Vertices(2).X = 100.0F : Vertices(2).Y = 150.0F : Vertices(2).Rhw = 1.0F : Vertices(2).Color = &HFFFF00 'Now, you can't just place vertices anywhere: you have to place them clockwise. 'Specifically, you have to place them so that their 'normal vector' or the 'face' points into the screen. 'The normal vector is a vector that lies perpendicular to the object. Since our triangle (and all triangles) 'is a 2D object, the normal can be on one side or the other. In order to determine which side is the 'face' or the 'normal', we use the right hand rule. Put your right wrist at the first vertex of the triangle. Place the tips of the 'four big fingers of your right hand (I hope you have four) at the second vertex (or at least, in its direction). 'Now, see if you can, while closing the open palm of your right hand into a fist, point those four fingers to the 'direction of the third vertex. If you can do this, then the direction of your thumb indicates the normal. 'In this case, if you could do this, then you didn't draw your triangle correctly: try switching the last two vertices. 'If the last vertex is on the knuckle side of your hand, you need to flip your hand over to get the thumb to point in the 'direction of the normal vector... but save your wrist: this just means the normal vector is in the opposite direction 'of your thumb... and in this case, if your thumb is on top and the last point is on your knuckle side, then your points 'are drawn correctly. If you have decent visualization of 3D, then you only need to figure out which side you have to 'be on the triangle for the points to appear clockwise - in this case, the direction that you are looking is the direction 'of the normal vector. Vertices(3) = New CustomVertex.TransformedColored(200.0F, 50.0F, 0.0F, 1.0F, &HFF0000) Vertices(4) = New CustomVertex.TransformedColored(300.0F, 150.0F, 0.0F, 1.0F, &HFF00) |

'It's important to unlock the vertex buffer, so that D9 can see what we put in there. VxB.Unlock() |

'So, we'd be drawing here. 'To draw a vertex buffer, we set the device to receive from a vertex stream. 'The data is ready to stream out of the vertex buffer into the device and the device should draw it onto the screen. D9.SetStreamSource(0, VxB, 0) 'StreamNumber is usually zero while we only have one vertex buffer that streams vertex data. 'Of course, we also have to tell it which vertex buffer to get vertex data from. 'Offset as 0 just tells the device how many vertices to skip before drawing. D9.VertexFormat = CustomVertex.TransformedColored.Format 'We also need to tell the device what kind of vertices to draw. 'We have not told the device which vertices these are (that was the vertex buffer). 'This could actually come out of the loop, but there will usually be many different types of vertex types 'set within this loop. D9.DrawPrimitives(PrimitiveType.TriangleFan, 0, 3) 'This tells how to connect the vertices. 'LineList just means that every pair of vertices are the endpoints of a line (segment) 'LineStrip draws a line for the first two points, and from then on, the last vertex is the first vertex 'of the next line: so the 2nd vertex would serve as the end of the first segment and the 'beginning of the next: vertex #3 is the end of the second segment. 'PointList: a list of vertices, of course. 'TriangleList - every triad of vertices forms a triangle. 'TriangleStrip - like LineStrip: the last two vertices work as the first two vertices for the next 'triangle. 'TriangleFan - the first vertex serves as the first vertex for all triangles drawn like this. 'Afterwards, the last vertex drawn becomes the second vertex for the next triangle (from then on, only one 'vertex is required to make the next triangle). 'PrimitiveType P (rimitive Count) related to N (umber of vertices) 'LineList N = 2P P = N\2 'LineStrip N = P + 1 P = N - 1 'PointList N = P P = N 'TriangleList N = 3P P = N\3 'TriangleStrip N = P + 2 P = N - 2 'TriangleFan N = P + 2 P = N - 2 |

.vb file