Microsoft DirectX 8.1 (Visual Basic)

Step 1: Defining a Custom Vertex Type

The Vertices sample project renders a 2-D triangle by using three vertices. This introduces the concept of the vertex buffer, which is a Microsoft® Direct3D® object that is used to store and render vertices. Vertices can be defined many different ways by specifying a custom vertex structure and corresponding custom flexible vector format (FVF). The format of the vertices in the Vertices sample project is shown in the following code fragment.

Private Type CUSTOMVERTEX
    x As Single         'x in screen space.
    y As Single         'y in screen space.
    z As Single         'normalized z.
    rhw As Single       'normalized z rhw.
    color As Long       'vertex color.
End Type

The structure above specifies the format of the custom vertex type. The next step is to define the FVF that describes the contents of the vertices in the vertex buffer. The following code fragment defines an FVF that corresponds with the custom vertex type created above.

Const D3DFVF_CUSTOMVERTEX = (D3DFVF_XYZRHW Or D3DFVF_DIFFUSE)

The Flexible Vertex Format Flags describes what type of custom vertex is being used. The Vertices sample project uses the D3DFVF_XYZRHW and D3DFVF_DIFFUSE flags, which tells the vertex buffer that the custom vertex type has a transformed point followed by a color component.

Now that the custom vertex format and FVF are specified, the next step is to fill the vertex buffer with vertices, as described in Step 2: Setting Up the Vertex Buffer.

Note  The vertices in the Vertices sample project are transformed, meaning that they are already in 2-D window coordinates. This means that the point (0,0) is at the top left hand corner and the positive x-axis is right and the positive y-axis is down. These vertices are also lit, which means that they are not using Direct3D lighting, but are supplying their own color.