Sign in to follow this  

texture alpha...

This topic is 4398 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 created a new texture from scratch and was using it for a sprite. Only problem is that it seems not to have alpha when drawing the sprite. Is there something I have to do? Thanks, -Devin

Share this post


Link to post
Share on other sites
You need to use scene blending. In DirectX, this is done with D3DRS_ALPHABLENDENABLE, D3DRS_SRCBLEND and D3DRS_DESTBLEND render states. In your case these should have the following values:

D3DRS_ALPHABLENDENABLE: TRUE
D3DRS_SRCBLEND: D3DBLEND_SRCALPHA
D3DRS_DESTBLEND: D3DBLEND_INVSRCALPHA

With these values the alpha channel of your texture will control the blending between your texture and the pixels that are already in the backbuffer, which it seems to be what you want.

Regards,

--Cucan

Share this post


Link to post
Share on other sites
Thanks, I have those values set. I created a render target and rendered a mesh to it. I then created a texture the size of the mesh bounds using the rendertarget flag. I then used StretchRectangle to copy from the rendered rendertarget to the texture. I'm using the texture as a sprite texture to render it into the scene. The sprites are black background even with the alpha flag set during sprite.begin.

I'm unsure, but I think the texture didn't have it's alpha set before I copied or it was removed during the copy from the render target.

Share this post


Link to post
Share on other sites
Are you using an alpha format for your render surface? If you are using MDX and the RenderToSurface helper class, you should make sure both the helper (the RenderToSurface object) and the texture you are rendering to have the same format with an alpha channel. Also when clearing the device for the render to surface pass, you'll have to use a clear color with a zero alpha value... I'm not entirely sure why you are copying the image from the render target to the texture. I always use the RenderToSurface helper class, so I can't tell for sure, but it seems off. Could you post some code?

You may also want to write out the texture to an image file with an alpha channel, PNG or TGA for example. This way you can check if you're texture has the alpha channel, since when you set the AlphaBlending flag on Sprite.Begin you should be ok there. You can write out a texture to a file using the TextureLoader helper class.

PS. I guessed you are using MDX, since you've posted about it a number of times. If you are, you should stick [MDX] in front of your title so we can help you better (i.e. so we don't have to guess). Just a friendly hint, no finger-pointing intended.

Share this post


Link to post
Share on other sites
I tried using RenderToSurface with a texture and it creates a garbled surface. Most of it renders correctly and some doesn't. I can't set the texture to any size other than the actuall backbuffer size either. Is this normal?

thanks,
-Devin

Share this post


Link to post
Share on other sites
OK, I got it to render to a texture surface. My texture surface is as big as the rendered mesh. But how do I set my view and matrices as such that it renders as the same size in both the backbuffer and the texture, since they are different sizes?

Share this post


Link to post
Share on other sites
I finally got the glow effect to work, but I had to create two textures, one as big as my screen and the other as big as the mesh. render to the screen sized one then copy to the other. it was the only way I could get the size correct.

Share this post


Link to post
Share on other sites
Sign in to follow this