pd3dDevice->SetRenderState(D3DRS_AMBIENT,D3DCOLOR_XRGB(36, 36, 36)); //设置环境光
<span style="margin: 0px; padding: 0px; border: none; background-color: rgb(245, 250, 226); font-family: Consolas, 'Courier New', Courier, mono, serif; line-height: 18px;">pd3dDevice->SetRenderState(D3DRS_SPECULARENABLE,</span><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: rgb(245, 250, 226); font-weight: bold; font-family: Consolas, 'Courier New', Courier, mono, serif; line-height: 18px;">true</span><span style="margin: 0px; padding: 0px; border: none; background-color: rgb(245, 250, 226); font-family: Consolas, 'Courier New', Courier, mono, serif; line-height: 18px;">); //启用镜面光,默认关闭</span>
typedef structD3DLIGHT9 { D3DLIGHTTYPE Type; //光源类型 D3DCOLORVALUE Diffuse; //漫反射 D3DCOLORVALUE Specular; //镜面反射 D3DCOLORVALUE Ambient; //环境光 D3DVECTOR Position; //光源位置 D3DVECTOR Direction; //光源方向 float Range; //光源光照范围,部分光照类型有用 float Falloff; float Attenuation0; //衰减系数0 float Attenuation1; //衰减系数1 float Attenuation2; //衰减系数2 float Theta; float Phi; } D3DLIGHT9,*LPD3DLIGHT; //Light结构体
typedef enumD3DLIGHTTYPE { D3DLIGHT_POINT = 1, D3DLIGHT_SPOT = 2, D3DLIGHT_DIRECTIONAL = 3, D3DLIGHT_FORCE_DWORD = 0x7fffffff } D3DLIGHTTYPE,*LPD3DLIGHTTYPE; //光源类型枚举值
HRESULT SetLight( //设置光源 [in] DWORD Index, //0-7,表示1到8个光源 [in] const D3DLIGHT9 *pLight );
HRESULT LightEnable( //启用光源 [in] DWORD LightIndex, [in] BOOL bEnable );
D3DLIGHT9 light; //点光源设置例子 ::ZeroMemory(&light,sizeof(light)); light.Type = D3DLIGHT_POINT;//点光源 light.Ambient = D3DXCOLOR(0.85f, 0.85f, 0.85f, 1.0f); light.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); light.Specular =D3DXCOLOR(0.35f, 0.35f, 0.35f, 1.0f); light.Position = D3DXVECTOR3(0.0f, 200.0f, 0.0f); light.Attenuation0 = 1.0f; light.Attenuation1 = 0.0f; light.Attenuation2 = 0.0f; light.Range = 500.0f; pd3dDevice->SetLight(0,&light); //设置光源 pd3dDevice->LightEnable(0,true); //启用光照
D3DLIGHT9 light; //方向光源设置例子 ::ZeroMemory(&light,sizeof(light)); light.Type = D3DLIGHT_DIRECTIONAL;//方向光源 light.Ambient = D3DXCOLOR(0.55f, 0.55f, 0.55f, 1.0f); light.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); light.Specular = D3DXCOLOR(0.37f, 0.37f, 0.37f, 1.0f); light.Direction = D3DXVECTOR3(1.0f, 0.0f, 0.0f); pd3dDevice->SetLight(0,&light); //设置光源 pd3dDevice->LightEnable(0,true); //启用光照
D3DLIGHT9 light; //聚光灯设置例子 ::ZeroMemory(&light,sizeof(light)); light.Type = D3DLIGHT_SPOT;//聚光灯光源 light.Position = D3DXVECTOR3(200.0f, 100.0f, 300.0f); light.Direction = D3DXVECTOR3(-1.0f, -1.0f, -1.0f); light.Ambient = D3DXCOLOR(0.33f, 0.33f, 0.33f, 1.0f); light.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); light.Specular = D3DXCOLOR(0.39f, 0.39f, 0.39f, 0.3f); light.Attenuation0 = 1.0f; light.Attenuation1 = 0.0f; light.Attenuation2 = 0.0f; light.Range = 400.0f; light.Falloff = 0.1f; light.Phi = D3DX_PI / 3.0f; light.Theta = D3DX_PI / 6.0f; pd3dDevice->SetLight(0,&light); //设置光源 pd3dDevice->LightEnable(0,true); //启用光照
<img src="http://img.my.csdn.net/uploads/201301/14/1358105267_5032.png" alt="" /><img src="http://img.my.csdn.net/uploads/201301/14/1358105298_6919.png" style="font-family: Arial, Helvetica, sans-serif;" alt="" /><img src="http://img.my.csdn.net/uploads/201301/14/1358105344_3447.png" alt="" />
typedef struct D3DMATERIAL9 { //材质结构体 D3DCOLORVALUE Diffuse; D3DCOLORVALUE Ambient; D3DCOLORVALUE Specular; D3DCOLORVALUE Emissive; float Power; //镜面反射指数,他的值越大,高光强度和周围亮度相差就越大 } D3DMATERIAL9, *LPD3DMATERIAL9;
HRESULT SetMaterial( //设置材质 [in] const D3DMATERIAL9 *pMaterial );
HRESULT GetMaterial( //获得当前材质 [out] D3DMATERIAL9 *pMaterial );
pd3dDevice->SetRenderState(D3DRS_NORMALIZENORMALS,true); //设置发现规范化
时间: 2024-10-24 21:05:29