Archived

This topic is now archived and is closed to further replies.

D3DXSprite and colorkey

This topic is 5510 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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()...

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites