//----------------------------------------------------------------------------- // Desc: 设置材质和灯光 //----------------------------------------------------------------------------- VOID SetupLights() { //设置材料属性, 只反射红光分量和绿光分量, 整体上看该物体材料反射黄色光 D3DMATERIAL9 mtrl; ZeroMemory( &mtrl, sizeof(D3DMATERIAL9) ); mtrl.Ambient.r = 1.0f; mtrl.Ambient.g = 1.0f; mtrl.Ambient.b = 0.0f; mtrl.Ambient.a = 1.0f; mtrl.Diffuse.r = 1.0f; mtrl.Diffuse.g = 1.0f; mtrl.Diffuse.b = 0.0f; mtrl.Diffuse.a = 0.5f; mtrl.Specular.r = 1.0f; mtrl.Specular.g = 1.0f; mtrl.Specular.b = 0.0f; mtrl.Specular.a = 1.0f; g_pd3dDevice->SetMaterial( &mtrl ); //设置一号光源为方向光,颜色为绿色 D3DXVECTOR3 vecDir; D3DLIGHT9 light1; ZeroMemory( &light1, sizeof(D3DLIGHT9) ); light1.Type = D3DLIGHT_DIRECTIONAL; light1.Diffuse.r = 0.0f; light1.Diffuse.g = 1.0f; light1.Diffuse.b = 0.0f; vecDir = D3DXVECTOR3(-10, 0 ,10); //方向光方向 D3DXVec3Normalize( (D3DXVECTOR3*)&light1.Direction, &vecDir ); g_pd3dDevice->SetLight( 0, &light1 ); //二号光源为点光源,颜色为红色 D3DLIGHT9 light2; ZeroMemory( &light2, sizeof(D3DLIGHT9) ); light2.Type = D3DLIGHT_POINT; light2.Diffuse.r = 1.0f; light2.Diffuse.g = 0.0f; light2.Diffuse.b = 0.0f; light2.Position= D3DXVECTOR3(10*sinf(timeGetTime()/350.0f) , 0, 10*cosf(timeGetTime()/350.0f) ); light2.Range = 100.0f; light2.Attenuation0 = 1.0f; g_pd3dDevice->SetLight( 1, &light2 ); //三号光源为方向光,颜色为绿色, *镜面反射* D3DXVECTOR3 vecDir3; D3DLIGHT9 light3; ZeroMemory( &light3, sizeof(D3DLIGHT9) ); light3.Type = D3DLIGHT_DIRECTIONAL; light3.Specular.r = 0.0f; light3.Specular.g = 1.0f; light3.Specular.b = 0.0f; light3.Specular.a = 1.0f; vecDir3 = D3DXVECTOR3(-10,0,10); D3DXVec3Normalize( (D3DXVECTOR3*)&light3.Direction, &vecDir3 ); g_pd3dDevice->SetLight( 2, &light3 ); //设置一定的环境光 g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x00505050); }
void CLcXSkinIns::Render() { HRESULT hr=-1; LPDIRECT3DDEVICE9 pDev = (LPDIRECT3DDEVICE9)LcDev_GetD3Device(); CLcXSkinSrc* pOrg = (CLcXSkinSrc*)m_pOrg; ID3DXEffect* pEft = pOrg->GetEffect(); // Setup the projection matrix D3DXMATRIX matProj; pDev->GetTransform(D3DTS_PROJECTION, &matProj); D3DLIGHT9 light; D3DXVECTOR3 vecLightDirUnnormalized(0.0f, -1.0f, 1.0f); ZeroMemory( &light, sizeof(D3DLIGHT9) ); light.Type = D3DLIGHT_DIRECTIONAL; light.Diffuse.r = 1.0f; light.Diffuse.g = 1.0f; light.Diffuse.b = 1.0f; D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecLightDirUnnormalized ); light.Position.x = 0.0f; light.Position.y = -1.0f; light.Position.z = 1.0f; light.Range = 1000.0f; pDev->SetLight(0, &light ); pDev->LightEnable(0, TRUE ); // Set Light for vertex shader D3DXVECTOR4 vLightDir( 0.0f, 1.0f, -1.0f, 0.0f ); D3DXVec4Normalize( &vLightDir, &vLightDir ); // for HLSL { pEft->SetMatrix( "mViewProj", &matProj); pEft->SetVector( "lhtDir", &vLightDir); } // for shader { // set the projection matrix for the vertex shader based skinning method D3DXMatrixTranspose(&matProj, &matProj); pDev->SetVertexShaderConstantF(2, (float*)&matProj, 4); pDev->SetVertexShaderConstantF(1, (float*)&vLightDir, 1); } if(m_pAC) m_pAC->AdvanceTime(m_fElapse, NULL); pOrg->UpdateFrameMatrices(m_pFrameOrg, &m_mtWld); pOrg->DrawFrame(m_pFrameOrg); static D3DXMATRIX mtI(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1); pDev->SetTransform(D3DTS_WORLD, &mtI); }
// //设置函数 // bool Setup() { PlaySound(L"3.wav", NULL, SND_FILENAME | SND_ASYNC|SND_LOOP); //====================================================================================================================== //GUI系统的一些设置 //====================================================================================================================== // 创建一些GUI系统 g_MainGUI = new D3DGUIClass(Device, WINDOW_WIDTH, WINDOW_HEIGHT); //主菜单页面 g_StartGUI = new D3DGUIClass(Device, WINDOW_WIDTH, WINDOW_HEIGHT); //开始新游戏页面 g_ControlGUI = new D3DGUIClass(Device, WINDOW_WIDTH, WINDOW_HEIGHT); //载入游戏页面 g_StoreGUI = new D3DGUIClass(Device, WINDOW_WIDTH, WINDOW_HEIGHT); //设置页面 // 给四个页面分别添加背景图 if(!g_MainGUI->AddBackground(L"maingui.jpg")) return false; if(!g_StartGUI->AddBackground (L"gameover.jpg")) return false ; if(!g_ControlGUI ->AddBackground(L"controlgui.jpg")) return false; if(!g_StoreGUI ->AddBackground(L"storegui.jpg")) return false; // 分别给四个页面添加字体 if(!g_MainGUI->CreateTextFont(L"微软雅黑", 28, &g_MainGUIFontID)) return false; if(!g_StartGUI->CreateTextFont(L"微软雅黑", 38, &g_StartGUIFontID)) return false; if(!g_ControlGUI ->CreateTextFont(L"微软雅黑", 38, &g_ControlGUIFontID)) return false; if(!g_StoreGUI ->CreateTextFont(L"微软雅黑", 38, &g_StoreGUIFontID)) return false; //---------------------------------【主菜单main页面相关的页面布局代码】---------------------- // 添加4个按钮,分别是开始游戏,载入进度,选项和退出游戏,每个按钮对应3幅图 if(!g_MainGUI->AddButton(BUTTON_START_ID, 0, 0, L"START_UP.png", L"START_OVER.png", L"START_DOWN.png")) return false; if(!g_MainGUI->AddButton(BUTTON_LOAD_ID, 0, 150, L"CONTROL_UP.png", L"CONTROL_OVER.png", L"CONTROL_DOWN.png")) return false; if(!g_MainGUI->AddButton(BUTTON_OPTION_ID,0, 330, L"STORE_UP.png", L"STORE_OVER.png", L"STORE_DOWN.png")) return false; if(!g_MainGUI->AddButton(BUTTON_QUIT_ID, 0, 475, L"THE_END_UP.png", L"THE_END_OVER.png", L"THE_END_DOWN.png"))return false ; //------------------------【开始新游戏start页面相关的页面布局代码】------------------------ if(!g_StartGUI->AddButton(BUTTON_LEVEL_1_ID,550, 1380, L"level1Up.png", L"level1Over.png", L"level1Down.png"))return false; if(!g_StartGUI->AddButton(BUTTON_BACK_ID, 650, 500, L"backUp.png", L"backOver.png", L"backDown.png")) return false; //------------------------【游戏操作介绍页面页面相关的页面布局代码】----------------------- // 添加按钮到页面中 if(!g_ControlGUI ->AddButton(BUTTON_BACK_ID, 650, 500, L"backUp.png", L"backOver.png", L"backDown.png")) return false; //------------------------【游戏设置option页面相关的页面布局代码】------------------------ // 添加按钮到页面中 if(!g_StoreGUI ->AddButton(BUTTON_BACK_ID,650, 500, L"backUp.png", L"backOver.png", L"backDown.png")) return false; //设定融合因子 Device->SetRenderState (D3DRS_SRCBLEND,D3DBLEND_SRCALPHA); Device->SetRenderState (D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA); //指定Alpha来源 Device->SetTextureStageState (0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE); Device->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG1); Device->SetRenderState(D3DRS_LIGHTING,true); Device->SetRenderState(D3DRS_NORMALIZENORMALS,true); d3d::BoundingBox boundingBox; boundingBox._min = D3DXVECTOR3(-500.0f, 0.0f, -500.0f); boundingBox._max = D3DXVECTOR3( 500.0f, 300.0f, 500.0f); snow = new Snow(&boundingBox, 20); snow->init(Device, L"花4.png"); skybox= new SkyBox(Device); skybox->LoadSkyTextureFromFile (L"frontsnow1.jpg",L"backsnow1.jpg",L"leftsnow1.jpg",L"rightsnow1.jpg",L"topsnow1.jpg",L"groundsnow1.jpg");//加载天空盒贴图 terrain=new Terrain(Device,"heighmap.raw", 200, 200, 60,0.0f);//创建一个地形类 terrain->loadTexture(L"ground.jpg"); snake=new Snake(Device); if(!snake->initSnake ()) ::MessageBox(0, L"InitSnake() - FAILED", 0, 0); props=new Props(Device); if(!props->initProps ()) ::MessageBox(0,L"InitProps()_FAILED" ,0,0); groundobject=new Ground (Device); groundobject->initObject (); D3DXVECTOR3 position; position.x =0.0f;position.y =0.0f;position.z =0.0f;//指定围墙中心位置 groundobject->createBird (position); gameui=new GameUI(Device);//游戏界面的UI if(!gameui->initPicture (L"分数.png",10.0f,10.0f,5.0f)) ::MessageBox(0,L"InitUI()_FAILED" ,0,0); if(!gameui->initTex(L"宋体")) ::MessageBox(0,L"InitFont()_FAILED" ,0,0); gameui2=new GameUI(Device);//游戏界面的UI if(!gameui2->initPicture (L"EventObjectIcon4.dds",600.0f,10.0f,1.5f)) ::MessageBox(0,L"InitUI()_FAILED" ,0,0); //设置投影变换 D3DXMATRIX proj; D3DXMatrixPerspectiveFovLH( &proj, D3DX_PI*0.5f, 800.0/600.0, 1.0f, 30000.0f ); Device->SetTransform (D3DTS_PROJECTION,&proj); D3DVIEWPORT9 VP={0,0,800,600,0,1}; Device->SetViewport (&VP); //设置材质 ::ZeroMemory(&mtrl,sizeof(mtrl)); D3DXCOLOR colorA=d3d::BLACK; D3DXCOLOR colorB=d3d::GREEN; D3DXCOLOR colorC=d3d::RED; D3DXCOLOR colorD=d3d::YELLOW; mtrl=d3d::IintMetirial(&colorA,&colorB,&colorC,&colorD,1.0f); Device->SetMaterial (&mtrl); //设置灯光 D3DLIGHT9 light; ::ZeroMemory(&light,sizeof(light)); D3DXCOLOR LightColor=d3d::GREEN ; D3DXVECTOR3 LightPosition (0.0f,0.0f,0.0f); light=d3d::InitPointlight(&LightPosition,&LightColor); Device->SetLight (0,&light); Device->LightEnable (0,true); Device->SetRenderState (D3DRS_CULLMODE,D3DCULL_NONE); skybox->InitSkyBox(20000.f);//初始化天空盒 //设置纹理过滤方式 Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); Device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); D3DXCreateTextureFromFile(Device,L"ground.jpg",&SnakeBodyTex); return true; }
//----------------------------------------------------------------------------- // Name: SetupLights() // Desc: Sets up the lights dawg. //----------------------------------------------------------------------------- VOID SetupLights() { // Directional light: D3DLIGHT9 light; ZeroMemory( &light, sizeof( D3DLIGHT9 ) ); light.Type = D3DLIGHT_DIRECTIONAL; light.Diffuse.r = 0.5f * sinf( timeGetTime() / 250.0f ) + 0.5f; light.Diffuse.g = 0.5f * sinf( timeGetTime() / 500.0f ) + 0.5f; light.Diffuse.b = 0.5f * sinf( timeGetTime() / 750.0f ) + 0.5f; light.Specular.r = 0.5f; light.Specular.g = 0.5f; light.Specular.b = 0.5f; light.Range = 10.0f; light.Attenuation0 = 0.0f; light.Attenuation1 = 0.0f; light.Attenuation2 = 1.0f; // Point light: D3DLIGHT9 light2; ZeroMemory( &light2, sizeof( D3DLIGHT9 ) ); light2.Type = D3DLIGHT_POINT; light2.Diffuse = D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f ); light2.Position = D3DXVECTOR3( 2.5f * sinf( timeGetTime() / 500.0f ), 0.0f, 2.5f * cosf( timeGetTime() / 500.0f ) ); light2.Specular.r = 1.0f; light2.Specular.g = 1.0f; light2.Specular.b = 1.0f; light2.Range = 5.0f; light2.Attenuation0 = 0.0f; light2.Attenuation1 = 0.0f; light2.Attenuation2 = 1.0f; // Spot light: D3DLIGHT9 light3; ZeroMemory( &light3, sizeof( D3DLIGHT9 ) ); light3.Type = D3DLIGHT_SPOT; light3.Diffuse = D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f ); light3.Position = D3DXVECTOR3( 0.0f, 0.0f, -10.0f ); light3.Direction = D3DXVECTOR3( 2.5f * sinf( timeGetTime() / 500.0f ), 0.0f, 10.0f ); light3.Specular.r = 1.0f; light3.Specular.g = 1.0f; light3.Specular.b = 1.0f; light3.Range = 10.0f; light3.Attenuation0 = 0.0f; light3.Attenuation1 = 1.0f; light3.Attenuation2 = 0.0f; light3.Phi = D3DXToRadian(30.0f); light3.Theta = D3DXToRadian(20.0f); light3.Falloff = 1.0f; Vector3 vecDir( cosf( timeGetTime() / 1000.0f ), 1.0f, sinf( timeGetTime() / 1000.0f ) ); vecDir.Normalise(); light.Direction.x = vecDir.x; light.Direction.y = vecDir.y; light.Direction.z = vecDir.z; switch ( g_ambientSetting ) { case 1: // Black / No ambient colour light.Ambient = D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.0f); light2.Ambient = D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.0f); light3.Ambient = D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.0f); break; case 2: // Red light.Ambient = D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f); //g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f) ); light2.Ambient = D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f); light3.Ambient = D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f); break; case 3: // Green light.Ambient = D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f); light2.Ambient = D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f); light3.Ambient = D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f); break; case 4: // Blue light.Ambient = D3DXCOLOR(0.0f, 0.0f, 1.0f, 1.0f); light2.Ambient = D3DXCOLOR(0.0f, 0.0f, 1.0f, 1.0f); light3.Ambient = D3DXCOLOR(0.0f, 0.0f, 1.0f, 1.0f); break; case 5: // White light.Ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); light2.Ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); light3.Ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); break; default: break; } switch ( g_lightingSetting ) { case 2: g_pd3dDevice->SetLight( 0, &light ); break; case 3: g_pd3dDevice->SetLight( 0, &light2 ); break; case 4: g_pd3dDevice->SetLight( 0, &light3 ); break; default: break; } // Finally, turn on some ambient light. g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x00202020 ); }
void LoadModels(void) { D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH( &matProj, D3DXToRadian(45.0f), 1920.0f / 1080.0f, 0.1f, 100.0f ); g_pd3dDevice_0->SetTransform( D3DTS_PROJECTION, &matProj ); g_pd3dDevice_0->SetRenderState( D3DRS_ZENABLE, TRUE ); g_pd3dDevice_0->SetRenderState( D3DRS_LIGHTING, TRUE ); g_pd3dDevice_0->SetRenderState( D3DRS_SPECULARENABLE, TRUE ); // Setup a material for the teapot ZeroMemory( &g_teapotMtrl, sizeof(D3DMATERIAL9) ); g_teapotMtrl.Diffuse.r = 1.0f; g_teapotMtrl.Diffuse.g = 1.0f; g_teapotMtrl.Diffuse.b = 1.0f; g_teapotMtrl.Diffuse.a = 1.0f; // Setup a simple directional light and some ambient... g_pLight0.Type = D3DLIGHT_DIRECTIONAL; g_pLight0.Direction = D3DXVECTOR3( 1.0f, 0.0f, 1.0f ); g_pLight0.Diffuse.r = 1.0f; g_pLight0.Diffuse.g = 1.0f; g_pLight0.Diffuse.b = 1.0f; g_pLight0.Diffuse.a = 1.0f; g_pLight0.Specular.r = 1.0f; g_pLight0.Specular.g = 1.0f; g_pLight0.Specular.b = 1.0f; g_pLight0.Specular.a = 1.0f; g_pd3dDevice_0->SetLight( 0, &g_pLight0 ); g_pd3dDevice_0->LightEnable( 0, TRUE ); g_pd3dDevice_0->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_COLORVALUE( 0.2f, 0.2f, 0.2f, 1.0f ) ); // Load up the teapot mesh... D3DXLoadMeshFromX( "teapot.x", D3DXMESH_SYSTEMMEM, g_pd3dDevice_0, NULL, NULL, NULL, NULL, &g_pTeapotMesh_0 ); CreateFont(); #ifndef TWO return; #endif D3DXMatrixPerspectiveFovLH( &matProj, D3DXToRadian(45.0f), 1920.0f / 1080.0f, 0.1f, 100.0f ); g_pd3dDevice_1->SetTransform( D3DTS_PROJECTION, &matProj ); g_pd3dDevice_1->SetRenderState( D3DRS_ZENABLE, TRUE ); g_pd3dDevice_1->SetRenderState( D3DRS_LIGHTING, TRUE ); g_pd3dDevice_1->SetRenderState( D3DRS_SPECULARENABLE, TRUE ); // Setup a material for the teapot ZeroMemory( &g_teapotMtrl, sizeof(D3DMATERIAL9) ); g_teapotMtrl.Diffuse.r = 1.0f; g_teapotMtrl.Diffuse.g = 1.0f; g_teapotMtrl.Diffuse.b = 1.0f; g_teapotMtrl.Diffuse.a = 1.0f; // Setup a simple directional light and some ambient... g_pLight0.Type = D3DLIGHT_DIRECTIONAL; g_pLight0.Direction = D3DXVECTOR3( 1.0f, 0.0f, 1.0f ); g_pLight0.Diffuse.r = 1.0f; g_pLight0.Diffuse.g = 1.0f; g_pLight0.Diffuse.b = 1.0f; g_pLight0.Diffuse.a = 1.0f; g_pLight0.Specular.r = 1.0f; g_pLight0.Specular.g = 1.0f; g_pLight0.Specular.b = 1.0f; g_pLight0.Specular.a = 1.0f; g_pd3dDevice_1->SetLight( 0, &g_pLight0 ); g_pd3dDevice_1->LightEnable( 0, TRUE ); g_pd3dDevice_1->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_COLORVALUE( 0.2f, 0.2f, 0.2f, 1.0f ) ); // Load up the teapot mesh... D3DXLoadMeshFromX( "teapot.x", D3DXMESH_SYSTEMMEM, g_pd3dDevice_1, NULL, NULL, NULL, NULL, &g_pTeapotMesh_1 ); }
//-----------------------------------【Object_Init( )函数】-------------------------------------- // 描述:渲染资源初始化函数,在此函数中进行要被渲染的物体的资源的初始化 //-------------------------------------------------------------------------------------------------- HRESULT Objects_Init(HWND hwnd) { //创建字体 if(FAILED(D3DXCreateFont(g_pd3dDevice, 36, 0, 0, 1000, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, _T("Calibri"), &g_pTextFPS))) return E_FAIL; if (FAILED(D3DXCreateFont(g_pd3dDevice, 20, 0, 1000, 0, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, _T("华文中宋"), &g_pTextAdaperName))) return E_FAIL; if (FAILED(D3DXCreateFont(g_pd3dDevice, 23, 0, 1000, 0, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, _T("微软雅黑"), &g_pTextHelper))) return E_FAIL; if (FAILED(D3DXCreateFont(g_pd3dDevice, 26, 0, 1000, 0, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, _T("黑体"), &g_pTextInfo))) return E_FAIL; LPD3DXBUFFER pAdjBuffer = NULL; LPD3DXBUFFER pMtrlBuffer = NULL; if (FAILED(D3DXLoadMeshFromX(L"Warden.X", D3DXMESH_MANAGED, g_pd3dDevice, &pAdjBuffer, &pMtrlBuffer, NULL, &g_dwNumMtrls, &g_pMesh))) //if (FAILED(D3DXLoadMeshFromX(L"miki.X", D3DXMESH_MANAGED, g_pd3dDevice, &pAdjBuffer, &pMtrlBuffer, NULL, &g_dwNumMtrls, &g_pMesh))) //if (FAILED(D3DXLoadMeshFromX(L"65.X", D3DXMESH_MANAGED, g_pd3dDevice, &pAdjBuffer, &pMtrlBuffer, NULL, &g_dwNumMtrls, &g_pMesh))) return E_FAIL; D3DXMATERIAL *pMtrls = (D3DXMATERIAL *)pMtrlBuffer->GetBufferPointer(); g_pMaterials = new D3DMATERIAL9[g_dwNumMtrls]; g_pTextures = new LPDIRECT3DTEXTURE9[g_dwNumMtrls]; for (DWORD i = 0; i < g_dwNumMtrls; i++) { g_pMaterials[i] = pMtrls[i].MatD3D; g_pMaterials[i].Ambient = g_pMaterials[i].Diffuse; g_pMaterials[i].Diffuse.a = 0.3f; g_pTextures[i] = NULL; //D3DXCreateTextureFromFileA(g_pd3dDevice, pMtrls[i].pTextureFilename, &g_pTextures[i]); } SAFE_RELEASE(pAdjBuffer); SAFE_RELEASE(pMtrlBuffer); D3DLIGHT9 light; ZeroMemory(&light, sizeof(light)); light.Type = D3DLIGHT_DIRECTIONAL; light.Ambient = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f); light.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); light.Specular = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f); light.Direction = D3DXVECTOR3(1.0f, 0.0f, 1.0f); g_pd3dDevice->SetLight(0, &light); g_pd3dDevice->LightEnable(0, true); g_pd3dDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true); g_pd3dDevice->SetRenderState(D3DRS_SPECULARENABLE, true); g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); g_pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS); g_pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, true); g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true); g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); g_pd3dDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); Matrix_Set(); return S_OK; }
void SetupLightingDX9(void) { // `取得Direct3D9裝置` LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9(); // `開啟打光功能` device->SetRenderState(D3DRS_LIGHTING, TRUE); // `開啟/關閉localviewer功能` device->SetRenderState(D3DRS_LOCALVIEWER, g_bLocalViewer ? TRUE:FALSE); // `開啟/關閉autonormalize功能` device->SetRenderState(D3DRS_NORMALIZENORMALS, g_bAutoNormalize ? TRUE:FALSE); // `設定環境光` device->SetRenderState(D3DRS_AMBIENT, ConvertToD3DCOLOR(g_vGlobal_AmbientLight)); // `指定反光能力的資料來源, 把它設為經由SetMaterial函式中來設定.` device->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL); device->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL); device->SetRenderState(D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL); device->SetRenderState(D3DRS_SPECULARENABLE, g_bSpecularReflection ? TRUE:FALSE); // `設定物件材質的反光能力` D3DMATERIAL9 mtrl; ZeroMemory( &mtrl, sizeof(mtrl) ); mtrl.Ambient = *(D3DCOLORVALUE*) &g_vMaterialAmbient; mtrl.Diffuse = *(D3DCOLORVALUE*) &g_vMaterialDiffuse; mtrl.Specular = *(D3DCOLORVALUE*) &g_vMaterialSpecular; mtrl.Emissive = *(D3DCOLORVALUE*) &g_vMaterialEmissive; mtrl.Power = g_fMaterialShininess; // `經由呼叫SetMaterial來設定材質` device->SetMaterial(&mtrl); // `設定光源` for ( int i=0; i<g_iNumLights; i++ ) { if ( g_Lights[i].m_bEnabled ) { // `打開這盞光` device->LightEnable(i, TRUE); // `D3D9經由設定D3DLIGHT9 struct來設定光源屬性` D3DLIGHT9 light; ZeroMemory( &light, sizeof(light) ); switch(g_Lights[i].m_eType) { case LIGHT_DIRECTIONAL: // `設定成方向光` light.Type = D3DLIGHT_DIRECTIONAL; light.Direction = *(D3DVECTOR *) &g_Lights[i].m_vDirection; break; case LIGHT_POINT: // `設定成點光源` light.Type = D3DLIGHT_POINT; // `設定位置` light.Position = *(D3DVECTOR *) &g_Lights[i].m_vPosition; // `隨距離的衰減值` // 1/(CONSTANT+LINEAR*d+QUADRATIC*d^2) // `公式中的CONSTANT, LINEAR, QUADRATIC值` light.Attenuation0 = g_Lights[i].m_vAttenuation[0]; light.Attenuation1 = g_Lights[i].m_vAttenuation[1]; light.Attenuation2 = g_Lights[i].m_vAttenuation[2]; break; case LIGHT_SPOT: // `設定成聚光燈` light.Type = D3DLIGHT_SPOT; // `設定位置` light.Position = *(D3DVECTOR *) &g_Lights[i].m_vPosition; // `設定方向` light.Direction = *(D3DVECTOR *) &g_Lights[i].m_vDirection; // `隨距離的衰減值` // 1/(CONSTANT+LINEAR*d+QUADRATIC*d^2) // `公式中的CONSTANT, LINEAR, QUADRATIC值` light.Attenuation0 = g_Lights[i].m_vAttenuation[0]; light.Attenuation1 = g_Lights[i].m_vAttenuation[1]; light.Attenuation2 = g_Lights[i].m_vAttenuation[2]; // `光柱圓錐的一半角度` light.Phi = FastMath::DegreeToRadian(g_Lights[i].m_fSpotlightCutoff); // `Inner Cone的角度, Inner Cone內部沒有角度衰滅.` light.Theta = FastMath::DegreeToRadian(g_Lights[i].m_fSpotLightInnerCone); // `光柱的角度衰滅值` light.Falloff = g_Lights[i].m_fSpotlightExponent; break; } // `光源的Ambient值` light.Ambient = *(D3DCOLORVALUE*) &g_Lights[i].m_vAmbientColor; // `光源的Diffuse值` light.Diffuse = *(D3DCOLORVALUE*) &g_Lights[i].m_vDiffuseColor; // `光源的Specular值` light.Specular = *(D3DCOLORVALUE*) &g_Lights[i].m_vSpecularColor; // `光源有效范圍, 在此把它設定成浮點數所容計的最大值.` light.Range = 1000.0f; // `用SetLight來設定光源屬性` device->SetLight(i, &light); } else { // `關閉這盞光` device->LightEnable(i, FALSE); } } }
bool InitVertexBuffer() { HRESULT hr; ID3DXBuffer *adjBuff = NULL; ID3DXBuffer *mtrlBuff = NULL; DWORD numMtrls = 0; // 메쉬 정보 로드 hr = D3DXLoadMeshFromXA( "../../media/bigship1.x", D3DXMESH_MANAGED, g_pDevice, &adjBuff, &mtrlBuff, 0, &numMtrls, &g_pMesh ); if (FAILED(hr)) return false; ///////////////////////////////////////////////////////////////////////////// // 매터리얼 설정 if( mtrlBuff && numMtrls > 0 ) { D3DXMATERIAL *mtrls = (D3DXMATERIAL*)mtrlBuff->GetBufferPointer(); for( int i=0; i < (int)numMtrls; ++i ) { mtrls[ i].MatD3D.Ambient = mtrls[ i].MatD3D.Diffuse; g_Mtrls.push_back( mtrls[ i].MatD3D ); if( mtrls[ i].pTextureFilename ) { IDirect3DTexture9 *tex = NULL; string filePath = "../../media/"; filePath += mtrls[ i].pTextureFilename; D3DXCreateTextureFromFileA( g_pDevice, filePath.c_str(), &tex ); g_Texture.push_back( tex ); } else { g_Texture.push_back( 0 ); } } } mtrlBuff->Release(); // 메쉬 최적화 hr = g_pMesh->OptimizeInplace( D3DXMESHOPT_COMPACT | D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_VERTEXCACHE, (DWORD*)adjBuff->GetBufferPointer(), (DWORD*)adjBuff->GetBufferPointer(), 0, 0 ); if (FAILED(hr)) return false; // 프로그레시브 메쉬 생성. hr = D3DXGeneratePMesh(g_pMesh, (DWORD*)adjBuff->GetBufferPointer(), 0, 0, 1, D3DXMESHSIMP_FACE, &g_pPMesh ); g_pMesh->Release(); g_pMesh = NULL; adjBuff->Release(); if (FAILED(hr)) return false; //DWORD maxFaces = g_pPMesh->GetMaxFaces(); //g_pPMesh->SetNumFaces( maxFaces ); D3DXCOLOR color(1,1,1,1); ZeroMemory(&g_Light, sizeof(g_Light)); g_Light.Type = D3DLIGHT_DIRECTIONAL; g_Light.Ambient = color * 0.4f; g_Light.Diffuse = color; g_Light.Specular = color * 0.6f; g_Light.Direction = *(D3DXVECTOR3*)&Vector3(0,-1,0); Matrix44 V; Vector3 camPos(0,0,-20); Vector3 lookAtPos(0,0,0); Vector3 dir = lookAtPos - camPos; dir.Normalize(); V.SetView(camPos, dir, Vector3(0,1,0)); g_pDevice->SetTransform(D3DTS_VIEW, (D3DXMATRIX*)&V); Matrix44 proj; proj.SetProjection(D3DX_PI * 0.5f, (float)WINSIZE_X / (float) WINSIZE_Y, 1.f, 1000.0f) ; g_pDevice->SetTransform(D3DTS_PROJECTION, (D3DXMATRIX*)&proj) ; g_pDevice->SetLight(0, &g_Light); // 광원 설정. g_pDevice->LightEnable( 0, // 활성화/ 비활성화 하려는 광원 리스트 내의 요소 true); // true = 활성화 , false = 비활성화 g_pDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true); g_pDevice->SetRenderState(D3DRS_SPECULARENABLE, true); return true; }
HRESULT Objects_Init() { //创建字体 D3DXCreateFont(g_pd3dDevice, 36, 0, 0, 1000, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, _T("Calibri"), &g_pTextFPS); D3DXCreateFont(g_pd3dDevice, 20, 0, 1000, 0, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, L"华文中宋", &g_pTextAdaperName); D3DXCreateFont(g_pd3dDevice, 23, 0, 1000, 0, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, L"微软雅黑", &g_pTextHelper); D3DXCreateFont(g_pd3dDevice, 26, 0, 1000, 0, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, L"黑体", &g_pTextInfor); //-------------------------------------------------------------------------------------- // 创建顶点缓存和索引缓存 //-------------------------------------------------------------------------------------- //创建顶点缓存 if (FAILED(g_pd3dDevice->CreateVertexBuffer(24 * sizeof(CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVertexBuffer, NULL))) { return E_FAIL; } // 创建索引缓存 if (FAILED(g_pd3dDevice->CreateIndexBuffer(36 * sizeof(WORD), 0, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &g_pIndexBuffer, NULL))) { return E_FAIL; } //-------------------------------------------------------------------------------------- // 【纹理绘制四步曲之二】:顶点的访问 //-------------------------------------------------------------------------------------- //填充顶点缓存 CUSTOMVERTEX* pVertices; if (FAILED(g_pVertexBuffer->Lock(0, 24 * sizeof(CUSTOMVERTEX), (void**)&pVertices, 0))) return E_FAIL; // 正面顶点数据 pVertices[0] = CUSTOMVERTEX(-10.0f, 10.0f, -10.0f, 0.0f, 0.0f); pVertices[1] = CUSTOMVERTEX(10.0f, 10.0f, -10.0f, 1.0f, 0.0f); pVertices[2] = CUSTOMVERTEX(10.0f, -10.0f, -10.0f, 1.0f, 1.0f); pVertices[3] = CUSTOMVERTEX(-10.0f, -10.0f, -10.0f, 0.0f, 1.0f); // 背面顶点数据 pVertices[4] = CUSTOMVERTEX(10.0f, 10.0f, 10.0f, 0.0f, 0.0f); pVertices[5] = CUSTOMVERTEX(-10.0f, 10.0f, 10.0f, 1.0f, 0.0f); pVertices[6] = CUSTOMVERTEX(-10.0f, -10.0f, 10.0f, 1.0f, 1.0f); pVertices[7] = CUSTOMVERTEX(10.0f, -10.0f, 10.0f, 0.0f, 1.0f); // 顶面顶点数据 pVertices[8] = CUSTOMVERTEX(-10.0f, 10.0f, 10.0f, 0.0f, 0.0f); pVertices[9] = CUSTOMVERTEX(10.0f, 10.0f, 10.0f, 1.0f, 0.0f); pVertices[10] = CUSTOMVERTEX(10.0f, 10.0f, -10.0f, 1.0f, 1.0f); pVertices[11] = CUSTOMVERTEX(-10.0f, 10.0f, -10.0f, 0.0f, 1.0f); // 底面顶点数据 pVertices[12] = CUSTOMVERTEX(-10.0f, -10.0f, -10.0f, 0.0f, 0.0f); pVertices[13] = CUSTOMVERTEX(10.0f, -10.0f, -10.0f, 1.0f, 0.0f); pVertices[14] = CUSTOMVERTEX(10.0f, -10.0f, 10.0f, 1.0f, 1.0f); pVertices[15] = CUSTOMVERTEX(-10.0f, -10.0f, 10.0f, 0.0f, 1.0f); // 左侧面顶点数据 pVertices[16] = CUSTOMVERTEX(-10.0f, 10.0f, 10.0f, 0.0f, 0.0f); pVertices[17] = CUSTOMVERTEX(-10.0f, 10.0f, -10.0f, 1.0f, 0.0f); pVertices[18] = CUSTOMVERTEX(-10.0f, -10.0f, -10.0f, 1.0f, 1.0f); pVertices[19] = CUSTOMVERTEX(-10.0f, -10.0f, 10.0f, 0.0f, 1.0f); // 右侧面顶点数据 pVertices[20] = CUSTOMVERTEX(10.0f, 10.0f, -10.0f, 0.0f, 0.0f); pVertices[21] = CUSTOMVERTEX(10.0f, 10.0f, 10.0f, 1.0f, 0.0f); pVertices[22] = CUSTOMVERTEX(10.0f, -10.0f, 10.0f, 1.0f, 1.0f); pVertices[23] = CUSTOMVERTEX(10.0f, -10.0f, -10.0f, 0.0f, 1.0f); g_pVertexBuffer->Unlock(); // 填充索引数据 WORD *pIndices = NULL; g_pIndexBuffer->Lock(0, 0, (void**)&pIndices, 0); // 正面索引数据 pIndices[0] = 0; pIndices[1] = 1; pIndices[2] = 2; pIndices[3] = 0; pIndices[4] = 2; pIndices[5] = 3; // 背面索引数据 pIndices[6] = 4; pIndices[7] = 5; pIndices[8] = 6; pIndices[9] = 4; pIndices[10] = 6; pIndices[11] = 7; // 顶面索引数据 pIndices[12] = 8; pIndices[13] = 9; pIndices[14] = 10; pIndices[15] = 8; pIndices[16] = 10; pIndices[17] = 11; // 底面索引数据 pIndices[18] = 12; pIndices[19] = 13; pIndices[20] = 14; pIndices[21] = 12; pIndices[22] = 14; pIndices[23] = 15; // 左侧面索引数据 pIndices[24] = 16; pIndices[25] = 17; pIndices[26] = 18; pIndices[27] = 16; pIndices[28] = 18; pIndices[29] = 19; // 右侧面索引数据 pIndices[30] = 20; pIndices[31] = 21; pIndices[32] = 22; pIndices[33] = 20; pIndices[34] = 22; pIndices[35] = 23; g_pIndexBuffer->Unlock(); //-------------------------------------------------------------------------------------- // 【纹理绘制四步曲之三】:纹理的创建 //-------------------------------------------------------------------------------------- D3DXCreateTextureFromFile(g_pd3dDevice, L"pal5q.jpg", &g_pTexture); // 设置材质 D3DMATERIAL9 mtrl; ::ZeroMemory(&mtrl, sizeof(mtrl)); mtrl.Ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); mtrl.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); mtrl.Specular = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); g_pd3dDevice->SetMaterial(&mtrl); D3DLIGHT9 light; ::ZeroMemory(&light, sizeof(light)); light.Type = D3DLIGHT_DIRECTIONAL; light.Ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); light.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); light.Specular = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f); light.Direction = D3DXVECTOR3(1.0f, 1.0f, 0.0f); g_pd3dDevice->SetLight(0, &light); //设置光源 g_pd3dDevice->LightEnable(0, true);//启用光照 // 设置渲染状态 g_pd3dDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true); //初始化顶点法线 g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); //开启背面消隐 g_pd3dDevice->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(36, 36, 36)); //设置一下环境光 return S_OK; }
HRESULT KGraphicsEngine::UpdateLight() { D3DLIGHT9 light; ZeroMemory( &light, sizeof(D3DLIGHT9) ); light.Type = D3DLIGHT_DIRECTIONAL; light.Diffuse.r = 1.0f; light.Diffuse.g = 1.0f; light.Diffuse.b = 1.0f; light.Ambient.r = 0.40f; light.Ambient.g = 0.40f; light.Ambient.b = 0.40f; if(g_cGraphicsTool.m_bSunSpecular) { light.Specular.r = 1.00f; light.Specular.g = 1.00f; light.Specular.b = 1.00f; } else { light.Specular.r = 0.00f; light.Specular.g = 0.00f; light.Specular.b = 0.00f; } D3DXVECTOR3 vecDir; g_cGraphicsTool.GetSunDirection(vecDir); /*D3DXVECTOR3 vecDir = D3DXVECTOR3(0, -1, 0 );*/ //D3DXVECTOR3 vecDir(0,0.3f,1); D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecDir ); light.Range = 50000.0f; g_pd3dDevice->SetLight( 0, &light ); g_pd3dDevice->LightEnable( 0, TRUE ); light.Type = D3DLIGHT_POINT; light.Diffuse.r = 0.90f; light.Diffuse.g = 0.70f; light.Diffuse.b = 0.60f; light.Ambient.r = 0.80f; light.Ambient.g = 0.80f; light.Ambient.b = 0.80f; light.Specular.r = 1.00f; light.Specular.g = 1.00f; light.Specular.b = 1.00f; light.Attenuation0 = 0.01f; light.Attenuation1 = 0.02f; light.Attenuation2 = 0; light.Range = 500.0f; vecDir = D3DXVECTOR3(400*sinf(timeGetTime()*0.001f) , 100, 400*cosf(timeGetTime()*0.001f) -2000 ); light.Position = vecDir ; g_pd3dDevice->SetLight( 1, &light ); g_pd3dDevice->LightEnable( 1, TRUE ); g_pd3dDevice->SetRenderState( D3DRS_CULLMODE , D3DCULL_CW ); g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE ); g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, g_cGraphicsTool.GetAmbient() ); g_pd3dDevice->SetRenderState( D3DRS_SPECULARENABLE , TRUE ); return S_OK; }
//-----------------------------------【Object_Init( )函数】-------------------------------------- // 描述:渲染资源初始化函数,在此函数中进行要被渲染的物体的资源的初始化 //-------------------------------------------------------------------------------------------------- HRESULT Objects_Init(HWND hwnd) { //创建字体 if(FAILED(D3DXCreateFont(g_pd3dDevice, 36, 0, 0, 1000, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, _T("Calibri"), &g_pTextFPS))) return E_FAIL; if (FAILED(D3DXCreateFont(g_pd3dDevice, 20, 0, 1000, 0, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, _T("华文中宋"), &g_pTextAdaperName))) return E_FAIL; if (FAILED(D3DXCreateFont(g_pd3dDevice, 23, 0, 1000, 0, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, _T("微软雅黑"), &g_pTextHelper))) return E_FAIL; if (FAILED(D3DXCreateFont(g_pd3dDevice, 26, 0, 1000, 0, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, _T("黑体"), &g_pTextInfo))) return E_FAIL; LPD3DXBUFFER pAdjBuffer = NULL; LPD3DXBUFFER pMtrlBuffer = NULL; if (FAILED(D3DXLoadMeshFromX(L"Warden.X", D3DXMESH_MANAGED, g_pd3dDevice, &pAdjBuffer, &pMtrlBuffer, NULL, &g_dwNumMtrls, &g_pMesh))) //if (FAILED(D3DXLoadMeshFromX(L"WYJ.X", D3DXMESH_MANAGED, g_pd3dDevice, &pAdjBuffer, &pMtrlBuffer, NULL, &g_dwNumMtrls, &g_pMesh))) return E_FAIL; D3DXMATERIAL *pMtrls = (D3DXMATERIAL *)pMtrlBuffer->GetBufferPointer(); g_pMaterials = new D3DMATERIAL9[g_dwNumMtrls]; g_pTextures = new LPDIRECT3DTEXTURE9[g_dwNumMtrls]; for (DWORD i = 0; i < g_dwNumMtrls; i++) { g_pMaterials[i] = pMtrls[i].MatD3D; g_pMaterials[i].Ambient = g_pMaterials[i].Diffuse; g_pTextures[i] = NULL; D3DXCreateTextureFromFileA(g_pd3dDevice, pMtrls[i].pTextureFilename, &g_pTextures[i]); } SAFE_RELEASE(pAdjBuffer); SAFE_RELEASE(pMtrlBuffer); g_pd3dDevice->CreateVertexBuffer(4 * sizeof(CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_MANAGED, &g_pVertexBuffer, 0); CUSTOMVERTEX *pVertices = NULL; g_pVertexBuffer->Lock(0, 0, (void **)&pVertices, 0); pVertices[0] = CUSTOMVERTEX(-500.0f, 0.0f, -500.0f, 0.0f, 1.0f, 0.0f, 0.0f, 50.0f); pVertices[1] = CUSTOMVERTEX(-500.0f, 0.0f, 500.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f); pVertices[2] = CUSTOMVERTEX(500.0f, 0.0f, -500.0f, 0.0f, 1.0f, 0.0f, 50.0f, 50.0f); pVertices[3] = CUSTOMVERTEX(500.0f, 0.0f, 500.0f, 0.0f, 1.0f, 0.0f, 50.0f, 0.0f); g_pVertexBuffer->Unlock(); D3DXCreateTextureFromFile(g_pd3dDevice, L"grass.jpg", &g_pTexture); D3DXCreateCylinder(g_pd3dDevice, 10.0f, 10.0f, 500.0f, 60, 60, &g_cylinder, 0); g_MaterialCylinder.Ambient = D3DXCOLOR(0.9f, 0.0f, 0.8f, 1.0f); g_MaterialCylinder.Diffuse = D3DXCOLOR(0.9f, 0.0f, 0.8f, 1.0f); g_MaterialCylinder.Specular = D3DXCOLOR(0.9f, 0.2f, 0.9f, 0.9f); g_MaterialCylinder.Emissive = D3DXCOLOR(0.0f, 0.0f, 0.9f, 1.0f); D3DLIGHT9 light; ZeroMemory(&light, sizeof(light)); light.Type = D3DLIGHT_DIRECTIONAL; light.Ambient = D3DXCOLOR(0.7f, 0.7f, 0.7f, 1.0f); light.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); light.Specular = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f); light.Direction = D3DXVECTOR3(1.0f, 0.0f, 0.0f); g_pd3dDevice->SetLight(0, &light); g_pd3dDevice->LightEnable(0, true); g_pd3dDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true); g_pd3dDevice->SetRenderState(D3DRS_SPECULARENABLE, true); g_pCamera = new CameraClass(g_pd3dDevice); g_pCamera->SetCameraPosition(&D3DXVECTOR3(0.0f, 200.0f, -300.0f)); g_pCamera->SetTargetPosition(&D3DXVECTOR3(0.0f, 300.0f, 0.0f)); g_pCamera->SetViewMatrix(); g_pCamera->SetProjMatrix(); g_pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); g_pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); g_pd3dDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); //g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); return S_OK; }