DirectX and color key transparency

Started by
5 comments, last by Whackjack 21 years, 1 month ago
In my Direct3D 8 book, the author says that DirectX doesn''t have a built-in way to color key transparency for loaded bitmaps. He instead uses a cumbersome function that he wrote that loads in each pixel of the bitmap one at a time and tests to see if it matches the predetermined color key. Is there truly not an API function that does this, or did the author just go out of his way to make things more complicated?
Advertisement
The author went out of his way to make a function of his own. If he SAYS there is no function, he either does not know, or wants you to think his way is better.

The D3DX Library has a function called D3DXCreateTextureFromFileEx, and there is a parameter there that askes for the color key.
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
Good. I was beginning to think D3DX was kinda stupid, especially if it couldn''t do color key transparency. Thanks for the help.
Check out this function, it simplifies stuff even more however before it ignores the pixels set the alpha test in your initializer like this
d3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, true);
d3dDevice->SetRenderState(D3DRS_ALPHAREF, 0x01);
d3dDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);

so here is the code. use it if it helps any.

LoadSurface(LPDIRECT3DSURFACE8* ppSurface, char *filename){		D3DCOLOR colourKey = D3DCOLOR_ARGB(0,255,0,255);	LPDIRECT3DSURFACE8 pSurface;	D3DXIMAGE_INFO srcInfo;    	PALETTEENTRY palette[256];	d3dDevice->CreateImageSurface(1, 1, d3dCFormat, &pSurface);	D3DXLoadSurfaceFromFile(pSurface, NULL, NULL, filename, NULL, D3DX_FILTER_NONE, 0, &srcInfo );	pSurface->Release();	d3dDevice->CreateImageSurface(srcInfo.Width, srcInfo.Height, 		d3dCFormat, ppSurface);	pSurface = *ppSurface;	D3DXLoadSurfaceFromFile(pSurface, palette, NULL, filename, 		NULL, D3DX_FILTER_NONE, colourKey, &srcInfo);} 


I think that code was from this site, but i forget
One quick note, in the code i posted d3dCFormat is actually just a variable for D3DFMT_A8R8G8B8 which is what should go there.
most likely the book your using is old

And was using DirectX around or up to 4
They didnt have color key transparency at that time, and was introduced later. Especially when using DirectDraw

If he is using DirectX 7+ , then yes he was misleading you.
<=- Talon -=>
Thanks for your input everyone. The author is using DX8, but I just think that he didn''t know about the color key transparency functions. It''s unfortunate too, because the function he built is disgustingly more complicated than it needs to be.

This topic is closed to new replies.

Advertisement