• Advertisement
Sign in to follow this  

alpha value of texture always be 1.0f

This topic is 683 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 use the tex2D of the hlsl to sample a texture.

the alpha value is always be 1.0.

I have manually lock the texture and set the rgba to 0,  the sampler can return rgb of (0,0,0) , but still return alpha of 1.0.....

 

 

here's the code I set the alpha of texture to 0:

 

if (SUCCEEDED(mTex2D->LockRect(0, &lockedRect, NULL, D3DLOCK_READONLY )))
{
m_pRGBAData = new DWORD[mWidth * mHeight];
if (m_pRGBAData != NULL)
{
for (DWORD y = 0; y < mWidth; y++)
{
DWORD dwOffset = y*mWidth;
yGrad = (int)(((float)y / (float)mWidth) * 255.0f);
 
for (DWORD x = 0; x < mWidth; x)
{
xGrad = (int)(((float)x / (float)mWidth) * 255.0f);
 
DWORD b = (DWORD)(xGrad + (255 - yGrad)) / 2 & 0xFF;
DWORD g = (DWORD)((255 - xGrad) + yGrad) / 2 &0xFF;
DWORD r = (DWORD)(xGrad + yGrad) / 2 & 0xFF;
//DWORD a = (DWORD)(xGrad + yGrad) / 2 & 0xFF;
DWORD *bits = (DWORD*)lockedRect.pBits;
assert(bits != 0);
//lockedRect.pBits[dwOffset + x] = ((a << 24L) + (r << 16L) + (g << 8L) + (b));
DWORD alpha = bits[dwOffset + x] >> 24;
bits[dwOffset + x] = 0;                                                        ///// set rgba to 0.
x++;
 
}
}
}

Share this post


Link to post
Share on other sites
Advertisement

You're also not unlocking the rect so the data would never go to the texture anyway.

I gave him the benefit of doubt on this issue :)

Share this post


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

  • Advertisement