Sign in to follow this  
bengaltgrs

Reading/Writing textures

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this