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

Updating a texture

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

	(*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);

	//read data from source texture

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


Share this post

Link to post
Share on other sites