Sign in to follow this  

Transparency & transformed coordinates

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

This topic is 4743 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.

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