Sign in to follow this  

Sprite

This topic is 4481 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

been meddling with dx for a few months now and still only at a very very basic level. ive just loaded a texture and got it on the screen with d3dxsprite, the image im using has a graphic in the middle but has a white background, how do i specify to alpha the white background. i understand as there is white in the image some of that will be transparent as well, this however will be sorted when i update my image with a unusual background colur like bright pink so how do i alpha the white? thanks

Share this post


Link to post
Share on other sites
What function are you using to load? If it's D3DXLoadTextureFromFileEX(or whatever it's called) then check out the "colourkey" parameter. Pure white in ARGB is 0xFFFFFFFF.

Share this post


Link to post
Share on other sites
D3DXCreateTextureFromFileEx(
g_lpD3DDevice,
"billboard.bmp",
D3DX_DEFAULT,
D3DX_DEFAULT,
D3DX_DEFAULT,
0,
D3DFMT_A1R5G5B5,
D3DPOOL_MANAGED,
D3DX_FILTER_TRIANGLE,
D3DX_FILTER_TRIANGLE,
D3DCOLOR_ARGB(255,255,255,255),
NULL,
NULL,
&g_lpD3DTXBillboard
);

set the ColorKey to D3DCOLOR_ARGB(255, 255, 255, 255) in order to make the background transparent.

Share this post


Link to post
Share on other sites
yes, it works nice one, im beginning to see, ok so if i wanted to pu another texture, would i have to call another createtexturefromfileex and load that in . . . seems a little bit over the top, is there a way to class this up? or would you do it another way?

Share this post


Link to post
Share on other sites
The way I make transparent backgrounds is make my sprite in Photoshop (or some other image tool that allows you to do this) and you can tell it to create a transparent background. I save the format as a png and when I call the begin function of the sprite interface I pass it D3DXSPRITE_ALPHABLEND. No color key involved.

I use this function to load in sprites, although I'm not sure why. I just did it once and copied and pasted it into my other projects. I think I might look into D3DXCreateTextureFromFile:


HRESULT GetSurfaceFromFile(LPCWSTR filename,
LPDIRECT3DSURFACE9 &pSurface)
{
HRESULT hr;
D3DXIMAGE_INFO imageInfo;

V_RETURN(D3DXGetImageInfoFromFile(filename, &imageInfo));

V_RETURN(DXUTGetD3DDevice()->
CreateOffscreenPlainSurface(imageInfo.Width,imageInfo.Height,
D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,
&pSurface,0));


V_RETURN(D3DXLoadSurfaceFromFile(pSurface,0,0,filename,
0,D3DX_DEFAULT,0,0));

return S_OK;
}


Share this post


Link to post
Share on other sites
ok, i see but for some reason the ALPHABLEND flag is unrecognised with min (its a direct copy from the codesampler tutorial) I realised that their Draw() didnt have enogh params so used msdn to find out what i was missing but on compile sprite->draw() will not let me put anything in there . . is there an include im missing cos otherwise its fine

Share this post


Link to post
Share on other sites
yea that is a good way to do it (the alphablending way) colorkeying just looks really bad... i do the same thing as njpaul; just save as a png or somethin'

as for the code


LPD3DXSPRITE sprite;

// begin scene
sprite->Begin(D3DXSPRITE_ALPHABLEND);

// draw the sprite, texture, rectange (NULL for whole texture), center, translation, color
sprite->Draw(texture, NULL, NULL, &pos, D3DCOLOR(a,r,g,b));
sprite->End;
// end scene
// present scene


Share this post


Link to post
Share on other sites

This topic is 4481 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this