Jump to content
  • Advertisement
Sign in to follow this  
poigwym

alpha value of texture always be 1.0f

This topic is 773 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

That code does not set the texel values, because you are using a read-only lock.

Share this post


Link to post
Share on other sites

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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!