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
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.
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.
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.
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?
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:
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;}
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
Are you saying that it won't let you include the alphablend flag in a draw call? You need to pass the alphablend flag into the Begin function.
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
as for the code
LPD3DXSPRITE sprite;// begin scenesprite->Begin(D3DXSPRITE_ALPHABLEND);// draw the sprite, texture, rectange (NULL for whole texture), center, translation, colorsprite->Draw(texture, NULL, NULL, &pos, D3DCOLOR(a,r,g,b));sprite->End;// end scene// present scene
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement