Step 3.1: Prepare Geometry

After you create the primary system objects used with DirectDraw and Direct3D, you can begin initializing the scene. The Triangle sample takes this opportunity to initialize geometry by defining vertices in an array of D3DVERTEX structure. Technically, you aren't required to set up the geometry at this time—you can do it anytime prior to calling rendering methods:

HRESULT App_InitDeviceObjects( LPDIRECT3DDEVICE3 pd3dDevice,
                               LPDIRECT3DVIEWPORT3 pvViewport )
{
    // Data for the geometry of the triangle. Note that this tutorial only
    // uses ambient lighting, so the vertices' normals are not actually used.
    D3DVECTOR p1( 0.0f, 3.0f, 0.0f );
    D3DVECTOR p2( 3.0f,-3.0f, 0.0f );
    D3DVECTOR p3(-3.0f,-3.0f, 0.0f );
    D3DVECTOR vNormal( 0.0f, 0.0f, 1.0f );
    
    // Initialize the 3 vertices for the front of the triangle
    g_pvTriangleVertices[0] = D3DVERTEX( p1, vNormal, 0, 0 );
    g_pvTriangleVertices[1] = D3DVERTEX( p2, vNormal, 0, 0 );
    g_pvTriangleVertices[2] = D3DVERTEX( p3, vNormal, 0, 0 );
    
    // Initialize the 3 vertices for the back of the triangle
    g_pvTriangleVertices[3] = D3DVERTEX( p1, -vNormal, 0, 0 );
    g_pvTriangleVertices[4] = D3DVERTEX( p3, -vNormal, 0, 0 );
    g_pvTriangleVertices[5] = D3DVERTEX( p2, -vNormal, 0, 0 );
 

The preceding code fragment defines three points in 3-D space that define a triangle that sits upright in the z=0 plane. After defining the geometry to be displayed, the Triangle sample prepares material and lighting parameters in Step 3.2: Set Up Material and Initial Lighting States.