| 
    
    //////////////////////////////////////////////////////////////////////////////////// 
    
    //                                                                                
    \\ 
    
    // This little function is called over and over again, and does the 
    rendering of  \\ 
    
    // our triangles...Its an all in one Pixel Shader function...the code has 
    been    \\ 
    
    // kept together for tutorial/explanation purposes...so you can see it in 
    action  \\ 
    
    // See how simple it really 
    is....                                                \\ 
    
    //                                                                                
    \\ 
    
    //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 
    
      
    
    void 
    Render() 
    { 
         
    if(!g_pd3dDevice)return;
     
      
         
    // NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW 
    NEW NEW NEW NEW NEW NEW NEW 
         
    // CHANGED CHANGED CHANGED CHANGED CHANGED CHANGED 
    CHANGED CHANGED CHANGED 
         
     
         
    const char 
    SimpleShader[] = 
          { 
    
                "vs.1.1                     // Shader version 1.1 \n" 
    
                "m4x4    oPos,  v0,  c0     // oPos-Output position, v0-Input 
    position, c0-Constant register\n" 
    
                "mov     oD0,   v5          // oDn-Output colour, v5-Input 
    colour value\n" 
          }; 
         
     
      
          
    DWORD dwDecl[] = 
          { 
    
                D3DVSD_STREAM(0), 
                
    D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), 
    
                D3DVSD_REG(D3DVSDE_DIFFUSE,  D3DVSDT_D3DCOLOR), 
    
                D3DVSD_END() 
          }; 
      
          
    DWORD dwShaderID; 
      
          
    ID3DXBuffer* pVS; 
      
          
    D3DXAssembleShader( SimpleShader, sizeof(SimpleShader)-1,
     
    
                                        0, NULL, &pVS, NULL ); 
      
          
    g_pd3dDevice->CreateVertexShader(dwDecl, (DWORD*)pVS->GetBufferPointer(), 
    
                                                           &dwShaderID, 0); 
         
     
         
    //g_pd3dDevice->SetVertexShader( dwShaderID ); 
    
      
         
    //g_pd3dDevice->DeleteVertexShader(dwDecl); 
         
    //pVS->Release(); 
    
      
       
      // NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW 
    NEW NEW NEW NEW NEW NEW NEW NEW NEW 
         
    // NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW 
    NEW NEW NEW NEW NEW NEW NEW 
         
    // These few extra lines are used to generate some 
    data and pass it to our 
         
    // vertex shader contant register, which we have 
    used above as c[0]. 
         
    // Again I've done the multiplication of the World 
    and Projection matrix's here 
         
    // so you get to see the principle of whats 
    happening...but wait until 
         
    // we pass more and more to our graphics 
    card...and really make it sweat! 
    
      
         
    // Setup the world, view, and projection matrices 
          
    WorldMatrices(); 
      
          
    D3DXMATRIX mat; 
          
    D3DXMatrixMultiply(&mat, &matWorld, &matView); 
          
    D3DXMatrixMultiply(&mat, &mat,      &matProj); 
          
    D3DXMatrixTranspose(&mat, &mat); 
       
     
         
    //                                         +--- 
    The data we are passing 
         
    //                                        \|/ 
       
      //                                         
    | 
          
    g_pd3dDevice->SetVertexShaderConstant(0, &mat, 4); 
         
    //                                    |        | 
         
    //                                   /|\      /|\ 
    
          //                                    |        +-- Number of 4 byte 
    chunks! 
       
      //                                    +-- 
    Constant Register c[0] 
             
     
         
    // NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW 
    NEW NEW NEW NEW NEW NEW NEW 
         
    // NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW 
    NEW NEW NEW NEW NEW NEW NEW 
    
      
    
      
         
    struct stVert 
          { 
    
                FLOAT x, y, z;  // D3DFVF_XYZ 
    
                DWORD colour;   // D3DFVF_DIFFUSE 
          }; 
          
    UINT myFVFFormat = D3DFVF_XYZ|D3DFVF_DIFFUSE ; 
      
          
    stVert myBox[]= 
          { 
    
                {-0.5f, -0.5f, 0.0f, 0xff00ff00}, 
    
                { 0.5f,  0.5f, 0.0f, 0xffff0000}, 
    
                {-0.5f,  0.5f, 0.0f, 0xff0000ff}, 
      
    
                {-0.5f, -0.5f, 0.0f, 0xffffff00}, 
    
                { 0.5f,  0.5f, 0.0f, 0xff00ff00}, 
    
                { 0.5f, -0.5f, 0.0f, 0xffff00ff} 
          }; 
      
          
    IDirect3DVertexBuffer8 * pVertexBuffer; 
          
    g_pd3dDevice->CreateVertexBuffer( 6*sizeof(stVert), 
    0,  
    
                                        myFVFFormat, D3DPOOL_MANAGED, &pVertexBuffer 
    ); 
      
         
    unsigned char 
    *p; 
        
    pVertexBuffer->Lock(0,0, &p, 0); 
        
    memcpy(p, myBox, 6*sizeof(stVert) ); 
        
    pVertexBuffer->Unlock(); 
      
         
    //Turn off lighting becuase we are specifying that 
    our vertices have colour 
        
    g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE); 
        
    g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE ); 
        
    g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE); 
      
       
    // Clear the backbuffer and the zbuffer 
        
    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,  
    
                                                D3DCOLOR_XRGB(0x00,0x00,0xff), 
    1.0f, 0 ); 
       
     
       
    // Draw our triangle. 
        
    g_pd3dDevice->SetStreamSource(0, pVertexBuffer, 
    sizeof(stVert)); 
         
     
        
    g_pd3dDevice->SetVertexShader( dwShaderID ); 
      
        
    g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2); 
      
       
    // End the scene 
        
    g_pd3dDevice->EndScene(); 
       
     
       
    // Present the backbuffer contents to the display 
        
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL ); 
      
        
    g_pd3dDevice->DeleteVertexShader(dwShaderID); 
        pVS->Release(); 
      
        
    pVertexBuffer->Release(); 
    } |