Jump to content
  • Advertisement
Sign in to follow this  
Fesh

Alpha Channel Transparency in D3D 7

This topic is 5400 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, is there anyone who knows of a good tutorial on how I can use alpha channel transparency effects in d3d7. I would like to use my 32 bit tga image in AARRGGBB format, load it to a texture and render the texture using the info in the 8 bit alpha channel to produce the correct amount of blending for that pixel. I am already familiar with how to use vertex alpha blending and stuff. I just need a few hints on what pixel format to specify when creating textures and what renderstates need to be set in order to accomplish the desired effect. Any help you could offer would be much appreciated. Cheers, Fesh

Share this post


Link to post
Share on other sites
Advertisement
Yes, its certainly possible. You need a texture format with an alpha channel (e.g. D3DFMT_A8R8G8B8), and you need to fill the alpha channel when you load. D3DXLoadtextureFromFile() will do that for you.

When you come to render, you need the following render states:
SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
SetRenderState(D3DRS_ZWRITEENABLE,FALSE);

And that should be all. Then you just render your objects in back-to-front order (otherwise the alpha doesn't work). To disable alpha blending, you just need to set D3DRS_ALPHABLENDENABLE to FALSE. You can leave the blending operations alone unless you need to change them elsewhere.

Share this post


Link to post
Share on other sites
Thx, but I was sorta hoping to do it using D3D 7, not 8. I wanted to use 7 because most of my code-base has already been written using d3d 7.

Share this post


Link to post
Share on other sites
Quote:
Original post by Fesh
Thx, but I was sorta hoping to do it using D3D 7, not 8. I wanted to use 7 because most of my code-base has already been written using d3d 7.
I thought the code was the same in D3D7? I don't have the DX7 docs to hand.

Share this post


Link to post
Share on other sites
Yeah, it's pretty different. I can't seem to find anywhere on the web where this specific topic is really discussed in detail either, does anyone know the reason for this?

Share this post


Link to post
Share on other sites
I just got the DX7 docs. The only difference is that in DX7, renderstate constants start D3DRENDERSTATE_ and not D3DRS_.
For texture formats, you just need a format with 8 bits of alpha (e.g. desc.ddpfPixelFormat.dwRGBAlphaBitMask = 0xff000000

Share this post


Link to post
Share on other sites
Thx, i sincerely appreciate it. I'll try to play around with it and see if I can get it to work.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!