Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Chaucer

Updating a texture

This topic is 5647 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''ve got a source texture that is created as a rendertarget and drawn to. I later would like to copy the data from this texture, darken it, and set its value to a new texture. I''m getting an access violation when I try to read the texture. Since this texture is required to be a rendertarget and not dynamic, I''m not sure how to handle. Here''s my source for updating the texture. Can anyone help?
  
void DarkenTexture(LPDIRECT3DTEXTURE8 *pSourceTexture, LPDIRECT3DTEXTURE8 *pDestTexture, int textureSize, int value)
{
	if(textureSize<0) return;
	if(!pSourceTexture) return;
	if(!pDestTexture) return;

	BYTE *pSourceData = new BYTE[textureSize*textureSize];

	//read data from source texture

	D3DLOCKED_RECT d3dlr;
	(*pSourceTexture)->LockRect(0, &d3dlr,0, D3DLOCK_READONLY);
	BYTE *pSourceBits = (BYTE*)d3dlr.pBits;
	int dataIndex=0;
	int bitIndex=0;
	for(int x=0;x<textureSize;x++)
	{
		for(int y=0;y<textureSize;y++)
			pSourceData[dataIndex++] = pSourceBits[bitIndex++];
		bitIndex += d3dlr.Pitch - (textureSize);
	}
	(*pSourceTexture)->UnlockRect(0);

	//read data from source texture

	(*pDestTexture)->LockRect(0, &d3dlr,0, 0);
	BYTE *pDestBits = (BYTE*)d3dlr.pBits;
	dataIndex=0;
	bitIndex=0;
	for(x=0;x<textureSize;x++)
	{
		for(int y=0;y<textureSize;y++)
		{
			if(pSourceData[dataIndex++] - value > 0)
				pDestBits[bitIndex++] = pSourceData[dataIndex++] - value;
			else
				pDestBits[bitIndex++] = 0;
		}
		bitIndex += d3dlr.Pitch - (textureSize);
	}
	(*pDestTexture)->UnlockRect(0);

}
  

Share this post


Link to post
Share on other sites
Advertisement

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