D3D Sprite Transparency problems (with screenshot examples)

Started by
3 comments, last by fluke 20 years, 1 month ago
i went through the trouble of putting this example together to show what problem i'm having rather than trying to explain it. however, to briefly explain, trying to implement transparency is causing the image to display incorrectly. it looks as though there is discoloration. http://user.7host.com/development/images/examples.gif here are the important snippets of code that make this work:

D3DXCreateTextureFromFileEx(pDevice,"ch1.bmp",256,256,0,0,D3DFMT_A1R5G5B5,D3DPOOL_DEFAULT,D3DX_FILTER_NONE,D3DX_FILTER_NONE,D3DCOLOR_RGBA(0,0,0,255),NULL,NULL,&pTexture1);
D3DXCreateTextureFromFileEx(pDevice,"ch2.bmp",256,256,0,0,D3DFMT_A1R5G5B5,D3DPOOL_DEFAULT,D3DX_FILTER_NONE,D3DX_FILTER_NONE,D3DCOLOR_RGBA(255,255,255,255),NULL,NULL,&pTexture2);
D3DXCreateTextureFromFileEx(pDevice,"bg1.bmp",256,256,D3DX_DEFAULT,0,D3DFMT_A1R5G5B5,D3DPOOL_MANAGED,D3DX_FILTER_NONE,D3DX_FILTER_NONE,D3DCOLOR_RGBA(0,0,0,255),NULL,NULL,&pBGTexture);

//adding or removing these next three lines doesn't help or hinder transparency or the problem.

		
pDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
pDevice->SetRenderState(D3DRS_ALPHAREF, 0x01);
pDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);

...

pSprite->Draw(pBGTexture,NULL,NULL,NULL,0.0f,&D3DXVECTOR2(0.0f,0.0f),0xFFFFFFFF); //background

RECT rc={0,0,17,17}; 
pSprite->Draw(pTexture1,&rc,NULL,NULL,0.0f,&D3DXVECTOR2(120.0f,183.0f),0xFFFFFFFF); //mario ex. 1	

pSprite->Draw(pTexture2,&rc,NULL,NULL,0.0f,&D3DXVECTOR2(140.0f,183.0f),0xFFFFFFFF); //mario ex. 2

 
I know there are several alternate methods to create transparency, (ie. loading surfaces to create textures, etc.) but i'd really like to get this working if possible. thanks in advance for your input. [edited by - fluke on March 18, 2004 9:05:43 AM]
Advertisement
Check out this tutorial that talks about the same issue. If you''ve already looked at this... I don''t have any better suggestions.



"Good code will come and go, but bad code sticks around."
"Good code will come and go, but bad code sticks around."
Offset either your quad or your UVs on the quad by half a texel, so you''re sampling the pixel center rather than the pixel edge (which will be filtered with the neighbouring pixels) Also, consider turning off filtering (set both D3DTSS_MINFILTER, D3DTSS_MAGFILTER to D3DTEXF_POINT).

To offset the UVs, for a 512x512 bitmap, use "+0.5f/512.0f".

If you''re using RHW coordinates, it might be easier to just offset those by 0.5f.
quote:Original post by TreborZehn
Check out this tutorial that talks about the same issue. If you''ve already looked at this... I don''t have any better suggestions.



"Good code will come and go, but bad code sticks around."


thanks, i already have this solution, which is more of a work-around...


and Namethatnobodyelsetook, thanks, i''m looking into that right now.
quote:Original post by Namethatnobodyelsetook
Offset either your quad or your UVs on the quad by half a texel, so you''re sampling the pixel center rather than the pixel edge (which will be filtered with the neighbouring pixels) Also, consider turning off filtering (set both D3DTSS_MINFILTER, D3DTSS_MAGFILTER to D3DTEXF_POINT).

To offset the UVs, for a 512x512 bitmap, use "+0.5f/512.0f".

If you''re using RHW coordinates, it might be easier to just offset those by 0.5f.


ha! it worked like a charm! i didn''t know antialising was on by default... a thousand thank-you''s!

This topic is closed to new replies.

Advertisement