Jump to content
  • Advertisement
Sign in to follow this  
amish1234

Transparency & transformed coordinates

This topic is 5028 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

Around midnight last night I started making a small game that I hoped to finish in one sitting. It uses sprites with DX8 by using transformed coordinates. (I have a float rhw member in my SpriteVertex struct). I'm trying to use a color key by loading the textures with D3DXCreateTextureFromFileEX and specifying a transparency color as a parameter. What actually happens to the sprites is that instead of the background image showing through, what SHOULD be transparent is actually black. I thought this might be due to the use of transformed coordinates, since D3D doesn't know which sprite is in front of the other, so I tried changing the z-coordinates to move a sprite in front of the background image, and discovered that anything with a z-coordinate other than zero doesn't show up. I realize DX9 has a Sprite class. However, I couldn't get my old dx9 projects to compile, so I used an old DX8 project as the base code. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Okay, I fixed it. I should have realized the z-order wasn't the problem, since D3D knows that from which order I render the sprites in. I forgot this:


D3DDevice->SetRenderState( D3DRS_CULLMODE,D3DCULL_CCW);
D3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
D3DDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
D3DDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);

Share this post


Link to post
Share on other sites
Because you're just colorkeying (ie: on or off alpha, no inbetweens) you may get better performance using alphatest (alphatestenable, alphafunc, alpharef renderstates). If you do want full blending (to render some tiles 50% transparent for example), you might want to support both alphatest and regular alphablend. If many sprites have large transparent areas you may still want to use alphatest along with alphablending to discard those pixels quicker.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!