Author Topic: Generate texture on the fly ( any colour )  (Read 1366 times)

0 Members and 1 Guest are viewing this topic.

MrMedic

  • Guest
Generate texture on the fly ( any colour )
« on: April 08, 2007, 07:08:17 pm »
for direct x starter kit ( 9 only ) 8 takes different set of par's

Code: (cpp) [Select]
//globals
LPDIRECT3DTEXTURE9 Red;

/////////////////////////////

HRESULT GenerateTexture(IDirect3DDevice9 *pD3Ddev, IDirect3DTexture9 **ppD3Dtex, DWORD colour32)
{
if( FAILED(pD3Ddev->CreateTexture(8, 8, 1, 0, D3DFMT_A4R4G4B4, D3DPOOL_MANAGED, ppD3Dtex, NULL)) )
 return E_FAIL;

WORD colour16 = ((WORD)((colour32>>28)&0xF)<<12)
  |(WORD)(((colour32>>20)&0xF)<<8)
  |(WORD)(((colour32>>12)&0xF)<<4)
  |(WORD)(((colour32>>4)&0xF)<<0);

D3DLOCKED_RECT d3dlr;   
(*ppD3Dtex)->LockRect(0, &d3dlr, 0, 0);
WORD *pDst16 = (WORD*)d3dlr.pBits;

for(int xy=0; xy < 8*8; xy++)
 *pDst16++ = colour16;

(*ppD3Dtex)->UnlockRect(0);

return S_OK;
}



///////////////////////////
HRESULT CD3DManager::Initialize()
{
GenerateTexture(m_pD3Ddev, &Red, D3DCOLOR_ARGB(255, 255, 0, 0)); // alpha .. red .. green .. blue



////////draw.ind..prim//////////////
m_pD3Ddev->SetTexture(0,Red);


there you go ... texture colouring on the fly

nice for disco chams .. @ taxman remember the 70's vc 2 disco balls lol