Sign in to follow this  
traiger

OpenGL newbie texture question

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Can anyone recommend A good tutorial or post on stages please.

Thanks

Paul

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites
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. :(

Share this post


Link to post
Share on other sites

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