D3DXSprite and colorkey

Started by
4 comments, last by sakic 21 years, 5 months ago
Until now I''ve succesfully used D3DXCreateTextureFromFileEx()to create a texture to use with the D3DXSprite interface to blit sprites on screen, with the color key as the transparent color. My problem is the following: I''ve made a Tile Editor that stores each image in a file with the map data, then in the game I load the map with the stored images. Since the images are stored all in a file I cannot use D3DXCreateTextureFromFileEx(), so I had to find another way... I tried to parse the images manually or with D3DXLoadSurfaceFromMemory(), both work, but I cannot set the color key anymore! I forgot: the format of the textures in the game is 16bit (565 or 555).. What operation does D3DXCreateTextureFromFileEx() perform on the texture to set the color key? Thanks for any help!
Unlimited2 Website:HereE-mail: [email=unlimited2@tin.it]unlimited2@tin.it[/email]
Advertisement
You can load in your textures without a color key and then once they are in memory you can set the color key. There is a file in your DX SDK called d3dutil.h. copy that file and include it with your project then there is a function in there call

HRESULT D3DUtil_SetColorKey( LPDIRECT3DTEXTURE8 pTexture, DWORD dwColorKey )

just give that function your texture and the color key, and it will fix the texture for you

:::Al:::
[Triple Buffer] - Resource leak imminent. Memory status: Fragile
[size=2]aliak.net
Thanks!

I''ll try this!
Unlimited2 Website:HereE-mail: [email=unlimited2@tin.it]unlimited2@tin.it[/email]
I''ve tried D3DUtil_SetColorKey() but it works only for the following formats:
D3DFMT_A4R4G4B4, D3DFMT_A1R5G5B5 and D3DFMT_A8R8G8B8....(those with an alpha channel).

So I''m still wondering what is the r,g,b value for a transparent pixel in the R5G6B5 texture mode...

I think I''m going to check the transparent pixel value of an image loaded with D3DXCreateTextureFromFileEx()...
Unlimited2 Website:HereE-mail: [email=unlimited2@tin.it]unlimited2@tin.it[/email]
Are you specifying a format with an alpha chennel when you load in the texture? because you cant expect to have transparency if the texture dosnt have an alpha channel, it''s no possible. It''s ok to have you imgaes as 16 non alpha or some other non alpha channel. But when you load them into directx you have to load them into a texture with an alpha channel..

  D3DCeateTextureFromFileEx(  pDevice,  "file.bmp",  0,  0,  0,  D3DFMT_A8R8G8B8,  MANAGED,  Linear,  Linear,  0xFF000000,  NULL,  NULL,  &pTexture)  


:::Al:::
[Triple Buffer] - Resource leak imminent. Memory status: Fragile
[size=2]aliak.net
Sorry, I made a stupid mistake: I thought the textures I used with D3DXCreateTextureFromFileEx() were R5G6B5, instead they were A1R5G5B5....

Now It''s all OK!


Thanks, again and sorry...
Unlimited2 Website:HereE-mail: [email=unlimited2@tin.it]unlimited2@tin.it[/email]

This topic is closed to new replies.

Advertisement