D3DXLoadSurfaceFromSurface Alpha

Started by
1 comment, last by amarhys 13 years ago
Hi everybody,

I am trying to patch a subset of an existing texture (let's call it texture A, size is 1536x1536) by a smaller texture (texture B, size is 64x64).

In fact, I want to replace a square area of 64x64 pixels in texture A by texture B.

To do that I did choose to use D3DXLoadSurfaceFromSurface and faced some trouble with Alpha blending. I am working with DirectX9.

a) First at all, what is strange is that when my texture B is fully opaque (alpha is 1.0 for all pixels), the surface loading is not visible (as if texture B was fully transparent) where as when texture B is fully transparent (alpha is 0.0 for all pixels) the surface loading seems to work perfectly (I can see the texture B in the 64x64 pixels area). Any idea on the root cause ? It seems to have the opposite behavior as expected no ?

Do texture stage settings have any impact on D3DXLoadSurfaceFromSurface function behavior ? I guess not because I tried many settings for alpha operations in texture stage and got always the same result.

b) I could use fully transparent texture B (alpha channel of texture B is useless in my case) but the issue is that if i use texture B with alpha set to 0.0, then at the end of the surface loading, the area of 64x64 pixels which has been replaced by texture B now has an alpha of 0.0, so fully transparent when I render the texture A. I don't want that !!

Then the question are :

1) is there a way to configure D3DXLoadSurfaceFromSurface to copy only R, G and B component of texture B, not taking care of texture B alpha channel, and to keep the alpha channel of texture A ? I tried to use a texture B which does not have alpha channel (DFMT_X8R8G8B8) but it seems to be considered as a fully opaque texture (no alpha is equivalent to alpha = 1.0) and does not work as explained in a).

2) If the answer to 1) is no, is there an another D3D function I missed in the documentation which could help me ?

Any help would be very appreciated, it makes me crazy.

Thanks in advance.

Cheers

amarhys




Advertisement
I am trying to patch a subset of an existing texture (let's call it texture A, size is 1536x1536) by a smaller texture (texture B, size is 64x64).

In fact, I want to replace a square area of 64x64 pixels in texture A by texture B.[/quote]

I cannot say anything about D3DXLoadSurfaceFromSurface() method.

But I can suggest you 2 different ways:
* Why don't you try "rendering to texture" ?. It's not complicated, I think.
* You can lock-unlock textures' bits then copy one from another.

hth.
-R
There's no "hard", and "the impossible" takes just a little time.
Thanks for your answer programci_84.

I am already using render to texture for other stuffs, I did not think about it but is is a good idea. I am going to try it.

Concerning lock - copy -unlock, isn't it runtime consuming ? I guess D3DXLoadSurfaceFromSurface is handled by the GPU whereas lock -> copy -> unlock is handle by the CPU, right ?




Thanks again.

This topic is closed to new replies.

Advertisement