Jump to content
  • Advertisement
Sign in to follow this  
ktuluorion

Transparency in a sprite

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

I have a d3dxsprite that I am displaying on the screen, but i'd like to draw another sprite on top of it except with a transparent color so that only parts of the other texture are displayed. How would I go about doing this?

Share this post


Link to post
Share on other sites
Advertisement
Two ways, one is colorkeying (no alpha transparency) ... simply choose a colorkey when loading the texture

Second, give the other texture an alpha map (photoshop etc), then activate alphablending in D3D:

m_pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
m_pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
m_pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

(note, if you use alpha transparency, you MUST draw them back to front, otherwise things will go crazy)

Share this post


Link to post
Share on other sites
The Begin method of D3DXSprite takes an alpha blend flag, that enables blending.

As mentioned above there are 2 typical ways to get the transparency in the sprite. Pre-edited (add alpha to the image) or set the colour key when you load the image with a function liek D3DXCreateTextureFromFileEx.

Share this post


Link to post
Share on other sites
This is somewhat related to the original question. Is there a way to dynamically set all of the pixel alpha values to a certain amount without directly accessing the bitmap in memory?

Share this post


Link to post
Share on other sites
Quote:
Original post by SKonen
This is somewhat related to the original question. Is there a way to dynamically set all of the pixel alpha values to a certain amount without directly accessing the bitmap in memory?


Uhm, out of thought that should be quite hard... as to do that you would need to send another image to the graphicscard which would be rendered to the other texture, but disabling RGB writes... I GUESS this would be possible, but really I don't see the point, as you eitherway are going to edit the picture, save the blit and state changes, just lock the texture and modify it as you will no matter what have to send just as much data anyway. So, you aren't really getting away from the cost eitherway.

Share this post


Link to post
Share on other sites
Use the color parameter of ID3DXSprite::Draw when you draw the sprite. Use D3DCOLOR_ARGB() to generate the color value, except pass in something other than 255 for A, such as D3DCOLOR_ARGB(128,255,255,255). This will make a half-transparent sprite.

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!