Jump to content
  • Advertisement
Sign in to follow this  
bengaltgrs

Reading/Writing textures

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

Does anyone know how to read/write texture files in DX9? I used to do this to save static shadow maps for terrain so I know it's possible, I just lost the code... Thanks in advance,

Share this post


Link to post
Share on other sites
Advertisement
Right, but I was referring to a method for actually looping through each pixel of a texture and changing it. Something similar to the following code:


D3DLOCKED_RECT data;
SomeTexture->LockRect(0, &data, 0, 0);

for(int i = 0; i < 512; i++)
{
for(int j = 0; j < 512; j++)
{

D3DXCOLOR c = ;//change texture pixel color here
}
}

SomeTexture->UnlockRect(0);



Like I said earlier, I used to use this method to save static shadows in the alpha channel of textures, I've just forgotten exactly how it was done.

Thanks,

Share this post


Link to post
Share on other sites
Nevermind, found the old code.. here it is for anyone interested in changing textures:


D3DLOCKED_RECT lockedRect;
Texture->LockRect(0, &lockedRect, 0, 0);

DWORD* imageData = (DWORD*)lockedRect.pBits;
for(int h = 0; h < 512; h++)
{
for(int j = 0; j < 512; j++)
{
D3DXCOLOR FinalColor = (D3DCOLOR)-(imageData[h * lockedRect.Pitch / 4 + j]);
imageData[h * lockedRect.Pitch / 4 + j] = (D3DCOLOR)FinalColor;
}
}


Texture->UnlockRect(0);
D3DXFilterTexture(Texture, 0, 0, D3DX_DEFAULT);



This particular code just inverts the color of each pixel.

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!