本文整理汇总了C++中IDirect3DDevice9::LightEnable方法的典型用法代码示例。如果您正苦于以下问题:C++ IDirect3DDevice9::LightEnable方法的具体用法?C++ IDirect3DDevice9::LightEnable怎么用?C++ IDirect3DDevice9::LightEnable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDirect3DDevice9
的用法示例。
在下文中一共展示了IDirect3DDevice9::LightEnable方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetUpLights
static void SetUpLights(){
IDirect3DDevice9 *pDevice = _pGraphics->GetD3DDevice();
D3DXVECTOR3 dir(1.0f, -1.0f, 1.0f);
D3DXCOLOR col(1.0f, 1.0f, 1.0f, 1.0f);
D3DLIGHT9 light;
light.Type = D3DLIGHT_DIRECTIONAL;
light.Ambient = col * 0.4f;
light.Diffuse = col;
light.Specular = col * 0.6f;
light.Direction = dir;
pDevice->SetLight(0, &light);
pDevice->LightEnable(0, true);
//pDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE );
pDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
//pDevice->SetRenderState(D3DRS_AMBIENT, 0xFFFFFFFF);
pDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true);
pDevice->SetRenderState(D3DRS_SPECULARENABLE, true);
}
示例2: Init
HRESULT APPLICATION::Init(HINSTANCE hInstance, int width, int height, bool windowed)
{
debug.Print("Application initiated");
//Create Window Class
WNDCLASS wc;
memset(&wc, 0, sizeof(WNDCLASS));
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)::DefWindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = "D3DWND";
//Register Class and Create new Window
RegisterClass(&wc);
m_mainWindow = CreateWindow("D3DWND", "Example 5.6: Frustum Culling", WS_EX_TOPMOST, 0, 0, width, height, 0, 0, hInstance, 0);
SetCursor(NULL);
ShowWindow(m_mainWindow, SW_SHOW);
UpdateWindow(m_mainWindow);
//Create IDirect3D9 Interface
IDirect3D9* d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
if(d3d9 == NULL)
{
debug.Print("Direct3DCreate9() - FAILED");
return E_FAIL;
}
//Check that the Device supports what we need from it
D3DCAPS9 caps;
d3d9->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps);
//Hardware Vertex Processing or not?
int vp = 0;
if(caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;
else vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
//Check vertex & pixelshader versions
if(caps.VertexShaderVersion < D3DVS_VERSION(2, 0) || caps.PixelShaderVersion < D3DPS_VERSION(2, 0))
{
debug.Print("Warning - Your graphic card does not support vertex and pixelshaders version 2.0");
}
//Set D3DPRESENT_PARAMETERS
D3DPRESENT_PARAMETERS d3dpp;
d3dpp.BackBufferWidth = width;
d3dpp.BackBufferHeight = height;
d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
d3dpp.BackBufferCount = 1;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.MultiSampleQuality = 0;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = m_mainWindow;
d3dpp.Windowed = windowed;
d3dpp.EnableAutoDepthStencil = true;
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
d3dpp.Flags = 0;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
//Create the IDirect3DDevice9
if(FAILED(d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_mainWindow,
vp, &d3dpp, &m_pDevice)))
{
debug.Print("Failed to create IDirect3DDevice9");
return E_FAIL;
}
//Release IDirect3D9 interface
d3d9->Release();
D3DXCreateFont(m_pDevice, 18, 0, 0, 1, false,
DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_DONTCARE, "Arial", &m_pFont);
//Create m_light
::ZeroMemory(&m_light, sizeof(m_light));
m_light.Type = D3DLIGHT_DIRECTIONAL;
m_light.Ambient = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
m_light.Diffuse = D3DXCOLOR(0.9f, 0.9f, 0.9f, 1.0f);
m_light.Specular = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
m_light.Direction = D3DXVECTOR3(0.0f, -1.0f, 0.0f);
m_pDevice->SetLight(0, &m_light);
m_pDevice->LightEnable(0, true);
//Set sampler state
for(int i=0;i<4;i++)
{
m_pDevice->SetSamplerState(i, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
m_pDevice->SetSamplerState(i, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
m_pDevice->SetSamplerState(i, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
}
//Init camera
m_camera.Init(m_pDevice);
//Load objects
LoadObjectResources(m_pDevice);
//.........这里部分代码省略.........
示例3: vEyePt
bool CScreen::SetDefaultGraphicsSettings3D()
{
HRESULT hr;
D3DXMATRIX identityTransform, projTransform;
D3DXMatrixIdentity(&identityTransform);
D3DXMatrixPerspectiveFovLH(&projTransform, D3DX_PI / 4, 1.0f, 1.0f, 100.0f);
D3DXVECTOR3 vEyePt(-10.0f, -10.0f, 10.0f);
D3DXVECTOR3 vLookatPt(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 vUpVec(0.0f, 0.0f, 1.0f);
D3DXMATRIXA16 matView;
D3DXMatrixLookAtLH(&matView, &vEyePt, &vLookatPt, &vUpVec);
D3DCOLORVALUE lightColor = {1.0f, 1.0f, 1.0f, 1.0f};
D3DXVECTOR3 lightDir(-1.0f, 0.7f, -0.2f);
D3DLIGHT9 light;
setupDirectionalLight(light, lightColor, lightDir);
D3DMATERIAL9 mtrl;
ZeroMemory( &mtrl, sizeof( D3DMATERIAL9 ) );
mtrl.Diffuse = lightColor;
mtrl.Ambient = lightColor;
mtrl.Ambient.g = 0.0f;
CGraphicsManager *pGraphicsManager = CGraphicsManager::GetInstance();
IDirect3DDevice9 *pDevice = pGraphicsManager->GetDevice();
CCamera * pCamera = CCamera::GetInstance();
hr = pDevice->SetTransform(D3DTS_WORLD, &identityTransform);
if(FAILED(hr))
{
LogErrorHr("Failed to set world transform", hr);
return false;
}
D3DXMATRIX camViewMat = pCamera->GetViewMatrix();
hr = pDevice->SetTransform(D3DTS_VIEW, &camViewMat);
if(FAILED(hr))
{
LogErrorHr("Failed to set view transform", hr);
return false;
}
D3DXMATRIX camProjMat = pCamera->GetProjectionMatrix();
hr = pDevice->SetTransform(D3DTS_PROJECTION, &camProjMat);
if(FAILED(hr))
{
LogErrorHr("Failed to set projection transform", hr);
return false;
}
hr = pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
if(FAILED(hr))
{
LogErrorHr("Failed to set cull mode render state", hr);
return false;
}
hr = pDevice->SetLight(0, &light);
if(FAILED(hr))
{
LogErrorHr("Failed to set light 0", hr);
return false;
}
hr = pDevice->SetMaterial(&mtrl);
if(FAILED(hr))
{
LogErrorHr("Failed to set material", hr);
return false;
}
hr = pDevice->LightEnable(0, TRUE);
if(FAILED(hr))
{
LogErrorHr("Failed to enable light", hr);
return false;
}
hr = pDevice->SetRenderState(D3DRS_AMBIENT, 0x00202020);
if(FAILED(hr))
{
LogErrorHr("Failed to set ambient color", hr);
return false;
}
hr = pDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
if(FAILED(hr))
{
LogErrorHr("Failed to enable z", hr);
return false;
}
hr = pDevice->SetRenderState(D3DRS_ZWRITEENABLE , TRUE);
if(FAILED(hr))
{
LogErrorHr("Failed to set z write enabled", hr);
return false;
//.........这里部分代码省略.........