http://hi.baidu.com/zyb_debug/blog/item/6719cde629879827b8382032.html
在前一篇中,发现自己解析的不是max建模出来的模型。 今天终于找到了问题,原因就是因为我用了CEGUI。 如果不用CEGUI的时候,模型完全正常。 但是CEGUI一旦render,那么开始出现非议所思的效果。
大家看看效果。 开启CEGUI状态之前的


开启CEGUI绘制之后的



我太汗了 究其原因。
就是CEGUI在绘制的时候改变了D3D绘制状态。
1 CEGUI::System::getSingleton().renderGUI(); 2 3 float fps = DXUTGetFPS(); 4 RenderFPS(fps); 5 6 RenderMesh(fElapsedTime); 7
所以要在绘制Mesh之前将d3d恢复至默认状态
写一个函数
1 //========================================= 2 /**//** 3 @brief 4 @param 建立此函数的目的主要是CEGUI在绘制的时候改了绘制状态 5 所以要把D3D所有的绘制状态改回去 6 @return 7 */ 8 //========================================= 9 10 void zybResetRenderState(IDirect3DDevice9* device) 11 { 12 13 device -> SetFVF(NULL); 14 15 // set device states 16 device -> SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); 17 device -> SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); 18 device -> SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); 19 device -> SetRenderState(D3DRS_ZWRITEENABLE, TRUE); 20 device -> SetRenderState(D3DRS_FOGENABLE, FALSE); 21 device -> SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); 22 23 24 // setup texture addressing settings/* 25 device -> SetSamplerState( 0 , D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP); 26 device -> SetSamplerState( 0 , D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP); 27 28 // setup colour calculations 29 //device -> SetTextureStageState( 0 , D3DTSS_COLORARG1, D3DTA_TEXTURE); 30 //device -> SetTextureStageState( 0 , D3DTSS_COLORARG2, D3DTA_CURRENT); 31 //device -> SetTextureStageState( 0 , D3DTSS_COLOROP, D3DTOP_SELECTARG1); 32 33 /**///// setup alpha calculations 34 //device -> SetTextureStageState( 0 , D3DTSS_ALPHAARG1, D3DTA_TEXTURE); 35 //device -> SetTextureStageState( 0 , D3DTSS_ALPHAARG2, D3DTA_CURRENT); 36 //device -> SetTextureStageState( 0 , D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); 37 38 /**///// setup filtering 39 //device -> SetSamplerState( 0 , D3DSAMP_MINFILTER, D3DTEXF_POINT); 40 //device -> SetSamplerState( 0 , D3DSAMP_MAGFILTER, D3DTEXF_POINT); 41 /**///// disable texture stages we do not need. 42 //device -> SetTextureStageState( 1 , D3DTSS_COLOROP, D3DTOP_DISABLE); 43 44 /**///// setup scene alpha blending 45 //device -> SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); 46 //device -> SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE); 47 //device -> SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ZERO); 48 49 }
最后绘制mesh的时候前面加个函数
1 CEGUI::System::getSingleton().renderGUI(); 2 3 float fps = DXUTGetFPS(); 4 RenderFPS(fps); 5 6 zyb::zybResetRenderState(DXUTGetD3D9Device()); 7 RenderMesh(fElapsedTime); 8
OK一切正常了
|