Sign in to follow this  

Reading/Writing textures

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

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

This topic is 3779 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.

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