資源描述:
《directX游戲編程實(shí)驗(yàn)四吳涼涼 2012329700012》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。
1、浙江理工大學(xué)《DirectX游戲編程》實(shí)驗(yàn)報(bào)告2013~2014學(xué)年第1學(xué)期學(xué)院信息學(xué)院班級(jí)12數(shù)字媒體技術(shù)1班姓名吳涼涼學(xué)號(hào)2012329700012任課教師(上課時(shí)間:第10周345節(jié))數(shù)字媒體技術(shù)專業(yè)2014年5月15日《DirectX游戲編程》實(shí)驗(yàn)報(bào)告實(shí)驗(yàn)名稱:DirectX彩色圖形繪制實(shí)驗(yàn)實(shí)驗(yàn)地點(diǎn):機(jī)1所使用的工具軟件及環(huán)境:安裝Windows操作系統(tǒng)(WindowsXp)和VC的1臺(tái)計(jì)算機(jī)。一、實(shí)驗(yàn)平臺(tái)lWindowsXPprofessional操作系統(tǒng)。lVC6.0集成開發(fā)環(huán)境.項(xiàng)目1:DirectX材質(zhì)和光照實(shí)驗(yàn)在例程Cube的基礎(chǔ)上,完成以下步驟:1
2、)實(shí)現(xiàn)平行光照明。2)黃色材質(zhì)設(shè)定。3)增加一個(gè)藍(lán)色點(diǎn)光源。4)實(shí)現(xiàn)材質(zhì)設(shè)定的透明度,實(shí)現(xiàn)50%透明度。在實(shí)驗(yàn)過程中注意燈光設(shè)置的方向、顏色等參數(shù)設(shè)定。項(xiàng)目2:DirectX紋理實(shí)驗(yàn)在項(xiàng)目1的程序基礎(chǔ)上完成一下步驟:1)給立方體增加紋理,圖片請(qǐng)自己準(zhǔn)備。2)制作alpha通道紋理圖,實(shí)現(xiàn)立方體的透明紋理。在實(shí)驗(yàn)過程中注意材質(zhì)的透明度對(duì)紋理設(shè)定的影響。二、實(shí)驗(yàn)代碼及結(jié)果1、黃色材質(zhì)設(shè)定。//Turnonlighting.Device->SetRenderState(D3DRS_LIGHTING,true);D3DMATERIAL9mtrl;mtrl.Ambient=d3
3、d::YELLOW;mtrl.Diffuse=d3d::YELLOW;mtrl.Specular=d3d::YELLOW;mtrl.Emissive=d3d::BLACK;mtrl.Power=5.0f;Device->SetMaterial(&mtrl);黃色材質(zhì)設(shè)定。1、實(shí)現(xiàn)平行光照明。D3DLIGHT9dir;::ZeroMemory(&dir,sizeof(dir));dir.Type=D3DLIGHT_DIRECTIONAL;dir.Diffuse=d3d::WHITE;dir.Specular=d3d::WHITE0.3f;dir.Ambient=d3d:
4、:WHITE0.6f;dir.Direction=D3DXVECTOR3(1.0f,0.0f,0.0f);Device->SetLight(0,&dir);Device->LightEnable(0,true);Device->SetRenderState(D3DRS_NORMALIZENORMALS,true);Device->SetRenderState(D3DRS_SPECULARENABLE,true);將語句:Device->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);注釋后得3、增加一個(gè)藍(lán)色點(diǎn)光源。D3
5、DXVECTOR3pos(0.0f,0.0f,5.0f);D3DXCOLORc=d3d::BLUE;D3DLIGHT9point=d3d::InitPointLight(&pos,&c);Device->SetLight(1,&point);Device->LightEnable(1,true);4、實(shí)現(xiàn)材質(zhì)設(shè)定的透明度,實(shí)現(xiàn)50%透明度。mtrl.Diffuse.a=0.5f;Device->CreateVertexBuffer(24sizeof(Vertex),D3DUSAGE_WRITEONLY,Vertex::FVF,D3DPOOL_MANAGED,&VB,0
6、);Device->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_DIFFUSE);Device->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG1);Device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);Device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);將原來的材質(zhì)改成白色:D3DMATERIAL9mtrl;mtrl.Ambien
7、t=d3d::WHITE;mtrl.Diffuse=d3d::WHITE;mtrl.Specular=d3d::WHITE;mtrl.Emissive=d3d::BLACK;mtrl.Power=5.0f;mtrl.Diffuse.a=0.5f;Device->SetMaterial(&mtrl);將點(diǎn)光源也改成白色:D3DXVECTOR3pos(1.0f,1.0f,0.0f);D3DXCOLORc=d3d::WHITE;D3DLIGHT9point=d3d::InitPointLight(&pos,&c);//SetandEnabletheligh