add sampler states

add light
add normals
This commit is contained in:
2025-11-12 12:24:37 +01:00
parent d78aec9c1a
commit 5e31638fb8
6 changed files with 95 additions and 53 deletions
+20 -1
View File
@@ -2,19 +2,38 @@
#include "Utilities.h"
#include "WICTextureLoader9.h"
using namespace DirectX;
UINT Material::init(IDirect3DDevice9* pD3DDevice, LPCWSTR textureFileName)
{
// load texture
// https://github.com/microsoft/DirectXTex/tree/main/WICTextureLoader
HRESULT hr = DirectX::CreateWICTextureFromFile(pD3DDevice, textureFileName, &_pTexture);
HRESULT hr = CreateWICTextureFromFile(pD3DDevice, textureFileName, &_pTexture, 0, WIC_LOADER_MIP_AUTOGEN);
CheckFailed(hr, 600);
// set material
D3DMATERIAL9 material = {};
material.Ambient = { 1.0f, 1.0f, 1.0f, 1.0f };
material.Diffuse = { 1.0f, 1.0f, 1.0f, 1.0f };
material.Specular = { 1.0f, 1.0f, 1.0f, 1.0f };
material.Emissive = { 0.0f, 0.0f, 0.0f, 1.0f };
material.Power = 512.0f;
pD3DDevice->SetMaterial(&material);
return 0;
}
void Material::render(IDirect3DDevice9* pD3DDevice)
{
// set texture
pD3DDevice->SetTexture(0, _pTexture);
// set sampler state
pD3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
pD3DDevice->SetSamplerState(0, D3DSAMP_BORDERCOLOR, D3DCOLOR_XRGB(255, 0, 255));
pD3DDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
pD3DDevice->SetSamplerState(0, D3DSAMP_MAXMIPLEVEL, 0);
}
void Material::deInit()