kenneth123

hi,
I'm using D3DXCreateTextureFromFile to display the picture,but i got some problem on it, the picture has a white color background, so i wish to make the white color background transparent. Last time a guy told me use the D3DXCreateTexture or D3DXLoadSurface, and it has a colorkey can make the color transparent,
but i not sure which one is the color key
Is it have any example can refer
How to load the picture file i want from my computer by using D3DXCreateTexture .

HRESULT D3DXCreateTexture( LPDIRECT3DDEVICE9 pDevice, UINT Width, UINT Height, UINT MipLevels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, LPDIRECT3DTEXTURE9 * ppTexture );


The code below is how i write the code in my program

void InitPlayingScene(IDirect3DDevice9* pd3dDevice)

{

D3DXCreateTextureFromFile( pd3dDevice, L"BKG.jpg", &g_pBKGTexture );

D3DXCreateSprite( pd3dDevice, &g_pBKGSprite);

D3DXCreateTextureFromFile( pd3dDevice, L"duck3.bmp", &g_pDuckTexture );

D3DXCreateSprite( pd3dDevice, &g_pDuckSprite);

}

void CALLBACK onPlayingSceneRender(IDirect3DDevice9* pd3dDevice)

{

DuckVec = D3DXVECTOR3(x, y, 0);

// render the background of the playing scene

SetRect(&rc, 0, 0, 120,60);

g_pDuckSprite ->Begin( D3DXSPRITE_DONOTSAVESTATE);

g_pDuckSprite ->Draw ( g_pDuckTexture, &rc, NULL, &DuckVec, 0xFFFFFFFF);

g_pDuckSprite ->End();

}





Re: Game Technologies: DirectX 101 The problem of D3DXCreateTexture

E.Jordan

I think you should look more carefully to the overloads, I am not a c++ Programmer so IL just paste you a pseudo code with one of the overloads I use in Managed DX< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

TextureLoader.FromFile(Device, File Path, Width (if known, otherwise just 0), Height (if known, otherwise just 0) , Mip Levels, Usage , Format if known, Pool, Filter, Filter, Int Transparent color to MASK)

Hope this helps

 

Erik

www.managedgames.com

Administrator

I think you should look more carefully to the overloads, I am not a c++ Programmer so IL just paste you a pseudo code with one of the overloads I use in Managed DX

TextureLoader.FromFile(Device, File Path, Width (if known, otherwise just 0), Height (if known, otherwise just 0) , Mip Levels, Usage , Format if known, Pool, Filter, Filter, Int Transparent color to MASK)

The C++ equivalent Function used to load a texture:

HRESULT D3DXCreateTextureFromFileEx(
  LPDIRECT3DDEVICE9 pDevice,
  LPCTSTR pSrcFile,
  UINT Width,
  UINT Height,
  UINT MipLevels,
  DWORD Usage,
  D3DFORMAT Format,
  D3DPOOL Pool,
  DWORD Filter,
  DWORD MipFilter,
  D3DCOLOR ColorKey,
  D3DXIMAGE_INFO * pSrcInfo,
  PALETTEENTRY * pPalette,
  LPDIRECT3DTEXTURE9 * ppTexture
);

 

But, he he, I think it will be easier to load the texture with the function U are using and then copy the surface and do the color keying during the copy function.

Hope this helps

 

Erik

www.managedgames.com

Administrator





Re: Game Technologies: DirectX 101 The problem of D3DXCreateTexture

kenneth123

Thanks, it really help a lot, at least i know which function i need to call, but i still not sure which parameter i have to change to make the background color transparent, i think should be the ColorKey parameter, and I tried to changed it to 0xFFFFFFFF (white color), because the picture background color is white, and i wish to make it transparent,but when i run the program agains, that white color background became black color. Below is the value i passed into D3DXCreateTextureFromFileEx just wondering what value i need to pass in if i want to make the white color transparent.


HRESULT D3DXCreateTextureFromFileEx( // value pas in my coding
LPDIRECT3DDEVICE9 pDevice, // ---> pd3dDevice
LPCTSTR pSrcFile, // ---> L"Duck.bmp",
UINT Width, // ---> 100
UINT Height, // ---> 50
UINT MipLevels, // ---> D3DX_DEFAULT
DWORD Usage, // ---> 0
D3DFORMAT Format, // ---> D3DFMT_FROM_FILE
D3DPOOL Pool, // ---> D3DPOOL_DEFAULT
DWORD Filter, // ---> D3DX_DEFAULT
DWORD MipFilter, // ---> DD3DX_DEFAULT
D3DCOLOR ColorKey, // ---> 0xFFFFFFFF
D3DXIMAGE_INFO * pSrcInfo, // ---> NULL
PALETTEENTRY * pPalette, // ---> NULL
LPDIRECT3DTEXTURE9 * ppTexture // ---> &g_pDuckTexture
);