newbie texture question

Started by
4 comments, last by traiger 18 years, 9 months ago
Hi I'm setting parts of a texture to transparent and saving as a .png file the only problem is that the transparent part of the texture is showing as black instead of transparent. Any ideas on how to make it acutally transparent? If it's anything like OpenGL I guess I have to enable blending or something.
Advertisement
Make sure you're specifying a texture format with an alpha channel when creating the texture and/or loading it (say via D3DXCreateTextureFromFileEx). Enable alphatesting if your file transparency is on/off or alphablending if the file has different degrees of transparency:

device->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
device->SetRenderState(D3DRS_ALPHAREF, 1);

The previous 2 lines of code will cause all texels with alpha < 1 (i.e. = 0) to be transparent.

Make sure you have the texture stage states setup correctly, too (i.e. that the stage alpha takes the texture alpha into account, either by selecting it or modulating it with some other alpha).

Can anyone recommend A good tutorial or post on stages please.

Thanks

Paul
The most common texture stage and render states are as follows, usually they fit the requirements. You can play around with the parameters to achieve some cool effects :)

device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

device->SetRenderState(D3DRS_ALPHABLENDENABLE, 1);//an obvious one :)

device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
device->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
Firstly thanks for not just posting a hyperlink to google, much appreciated.

This isn't much different OpenGL's glBlendFunc() wonder why I can't get it to bloody work then. :(
Cracking that did it thanks, Mephysto ratings to you and Coder for you help.

This topic is closed to new replies.

Advertisement