Make an existing IDirect3DTexture9 texture transparent

Started by
4 comments, last by janta 17 years, 10 months ago
I have a pointe to a IDirect3DTexture9, lets say as: IDirect3DTexture9* pMyTexture; ... but, I would like to make this texture transparent. How would I do this?
Advertisement
There is no one single way to make a texture transparent. It requires some knowledge of what the state of Direct3D is. E.g. what blending mode is being used? How about alpha testing? To what degree do you want it transparent? Completely? Partially? A mixture of the two?
.
ah, maybe I understand the question differently than mastaba, so i'll try another bullet:

You'd have to lock the texture's primary surface (assuming it's lockable, so if it is a SYSTEM texture - like a render target - forget it) Then you'd loop inot each pixel and modify their color value like (assumong ARGB)

oldColor = (oldColor & 0x00FFFFFF) | (alpha << 24); // alpha being a byte

The fact is, dont even think of doing thatonce per frame (unless you want a slide show but in such a case use MS powerpoint ;-)

Cheers, I hope that helped a bit
Janta
well, once I make the texture transparent in a frame, I will not make it transparent again. How do I get the primary surface?, do you mean LockRect(...)?
darn, I cannot edit that previous post.

I want the texture partially transparent.
The solution I proposed will work if you have one texture and want to change its opacity once and for all (or say, once in a while) and use that texture as such.

If you use alpha = 128, your texture will be half transparent for example.
Also, all the texture's pixel dont have to have the same alph, so you can play with differences...

And yup, I did meant LockRect(0, &lockedRect, NULL, 0); for example. Google for some example of how to youse, that wiped out of my mind sorry :)

Good luck.

This topic is closed to new replies.

Advertisement