Jump to content
  • Advertisement
Sign in to follow this  
MTclip

getting at the alpha channel of a LPDIRECT3DTEXTURE9??

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

.. if I have a LPDIRECT3DTEXTURE9 that has already been created.. and I know it has an alpha channel ... how can I access the alpha channel and read the color of each pixel... ?

Share this post


Link to post
Share on other sites
Advertisement
Okay so I have the portion of the texture locked and have the pitch and
the bits...

Im not so sure what to do next how would i actually go about searching the data for the alpha...

..im still looking but if anyone wants to leand a helping hand... ;)


//LOCKS RECT FOR THE TEXTURE
pLevel->m_vTextures->getTexture()->LockRect(0,&alphaRect,&frameRect,D3DLOCK_READONLY)))
{ // TEST FOR FAILURE
MessageBox(NULL," TEXTURE FAILED TO LOCK","DIRECT X ERROR",MB_OK);
PostQuitMessage(0);
}
// MY DATA
alphaRect.pBits;
alphaRect.Pitch;



Share this post


Link to post
Share on other sites
I'll assume that your texture has a format of D3DFMT_A8R8G8B8, since that's the easiest thing to work with. If it is, then we can more or less treat pBits as an array of D3DCOLOR elements. Well, more accurately, we should merely assume that pBits points to a a single row of D3DCOLOR elements. To get to the next row, we must add Pitch to pBits. Some code to go through all the pixels could look like this:

D3DSURFACE_DESC SurfaceDesc;
D3DLOCKED_RECT LockedRect;
pTexture->GetLevelDesc(0, &SurfaceDesc);
pTexture->LockRect(0, &LockedRect, NULL, Flags);

for (int y = 0; y < SurfaceDesc.Height; ++y)
{
D3DCOLOR* pRow = (D3DCOLOR*)(LockedRect.pBits + LockedRect.Pitch * y);
for (int x = 0; x < SurfaceDesc.Width; ++x)
{
//To set the whole color
pRow[x] = D3DCOLOR_ARGB(255, 255, 0, 0); //Set it to opaque red

//To get the whole color
D3DCOLOR c = pRow[x];

//To set the alpha channel
pRow[x] = (pRow[x] & 0x00FFFFFF) | (128 << 24); //Set the alpha to 128

//To get the alpha channel
BYTE a = (pRow[x] & 0xFF000000) >> 24;
}
}

pTexture->UnlockRect(0);

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!