Transparency in a sprite

Started by
4 comments, last by Drakex 18 years, 9 months ago
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?
[Piebert Entertainment] [Ask The All-Knowing Oracle A Question]------------------------------------------------------------GDSFUBY GameDev Society For UnBanning YodaTheCodaIf you want to see yoda unbanned then put this in your sig ------------------------------------------------------------DAIAGA Dave Astle is a God Association. To join, put this in your sig!Founder and High Priest of DAIAGA[edited by - YodaTheCoda on December 10, 2003 1:57:54 PM]
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)


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.
Stay Casual,KenDrunken Hyena
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?
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.


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.
_______________________________________________________________________Hoo-rah.

This topic is closed to new replies.

Advertisement