• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天行健 君子當(dāng)自強(qiáng)而不息

            D3D Animation Basis(8)

            Drawing Meshes

            Now that you have your meshes loaded and you've updated those skinned meshes that needed updating, it is time to throw some pixels at the display and show off those meshes! In total, I have created four mesh−rendering functions to help you in your projects.

            HRESULT draw_mesh(D3DXMESHCONTAINER_EX* mesh_container)
            {
                
            // error checking

                
            if(mesh_container == NULL)
                    
            return E_FAIL;

                
            if(mesh_container->MeshData.pMesh == NULL)
                    
            return E_FAIL;

                
            if(mesh_container->NumMaterials == 0 || mesh_container->pMaterials == NULL)
                    
            return E_FAIL;

                
            // get the device interface
                IDirect3DDevice9* device;
                mesh_container
            ->MeshData.pMesh->GetDevice(&device);

                
            // release vertex shader if being used
                device->SetVertexShader(NULL);
                device
            ->SetVertexDeclaration(NULL);

                DWORD last_alpha_blend, old_alpha_blend, old_src_blend, old_dest_blend;

                
            // save render states
                device->GetRenderState(D3DRS_ALPHABLENDENABLE,    &old_alpha_blend);
                device
            ->GetRenderState(D3DRS_SRCBLEND,            &old_src_blend);
                device
            ->GetRenderState(D3DRS_DESTBLEND,            &old_dest_blend);
                last_alpha_blend 
            = old_alpha_blend;

                
            // setup pointer for mesh to draw, either regular or skinned.
                ID3DXMesh* mesh_to_draw = (mesh_container->skin_mesh == NULL) ? 
                                          mesh_container
            ->MeshData.pMesh : mesh_container->skin_mesh;

                
            // look through all subsets
                for(DWORD i = 0; i < mesh_container->NumMaterials; i++)
                {
                    
            // set material and texture
                    device->SetMaterial(&mesh_container->pMaterials[i].MatD3D);
                    device
            ->SetTexture(0, mesh_container->textures[i]);

                    
            // enable or disable alpha blending per material
                    if(mesh_container->pMaterials[i].MatD3D.Diffuse.a != 1.0f)
                    {
                        
            if(last_alpha_blend != TRUE)
                        {
                            last_alpha_blend 
            = TRUE;

                            device
            ->SetRenderState(D3DRS_ALPHABLENDENABLE,    TRUE);
                            device
            ->SetRenderState(D3DRS_SRCBLEND,            D3DBLEND_ONE);    // src color
                            device->SetRenderState(D3DRS_DESTBLEND,            D3DBLEND_DESTCOLOR);
                        }
                    }
                    
            else
                    {
                        
            if(last_alpha_blend != FALSE)
                        {
                            last_alpha_blend 
            = FALSE;
                            device
            ->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
                        }
                    }

                    mesh_to_draw
            ->DrawSubset(i);
                }

                
            // restore alpha blending states
                if(last_alpha_blend != old_alpha_blend)
                {
                    device
            ->SetRenderState(D3DRS_ALPHABLENDENABLE, old_alpha_blend);
                    device
            ->SetRenderState(D3DRS_SRCBLEND,           old_src_blend);
                    device
            ->SetRenderState(D3DRS_DESTBLEND,           old_dest_blend);
                }
                
                
            // make sure to release the device object!
                device->Release();

                
            return S_OK;
            }

             

            If a material being used specifies an alpha value other than 1, then alpha blending is enabled. This way, you can specify portions of a mesh to use alpha blending by merely changing the material information. Also, if a D3DXMESHCONTAINER_EX object contains a skinned mesh, that mesh is rendered instead of the regular mesh.

            posted on 2008-04-15 11:16 lovedday 閱讀(314) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            公告

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關(guān)鏈接

            搜索

            最新評論

            波多野结衣中文字幕久久 | 久久久久无码国产精品不卡| 久久66热人妻偷产精品9| 成人妇女免费播放久久久| 91久久国产视频| 久久妇女高潮几次MBA| 国产精品青草久久久久婷婷| 性高朝久久久久久久久久| 香蕉久久夜色精品升级完成| 欧美一区二区精品久久| 久久久无码精品亚洲日韩京东传媒| 久久精品黄AA片一区二区三区| 久久精品国产一区二区电影| 国产69精品久久久久9999APGF | 国产一区二区三区久久精品| 久久精品成人免费观看97| 热99RE久久精品这里都是精品免费 | 久久影院亚洲一区| 欧美丰满熟妇BBB久久久| 伊人久久一区二区三区无码| 精品精品国产自在久久高清 | 国产91色综合久久免费分享| 日韩中文久久| 99热热久久这里只有精品68| 精品熟女少妇av免费久久| 久久亚洲精品国产亚洲老地址| 国产成人精品久久免费动漫 | 亚洲国产精品18久久久久久| 亚洲综合婷婷久久| 91久久成人免费| 亚洲国产天堂久久综合网站 | 成人久久精品一区二区三区| 国产成年无码久久久免费| 香蕉久久久久久狠狠色| 久久国产福利免费| 久久精品国产精品亚洲| 国产—久久香蕉国产线看观看| 青青青青久久精品国产| 99久久国产综合精品五月天喷水| 国产成人久久精品一区二区三区| 午夜欧美精品久久久久久久|