Advertisement Jump to content
Sign in to follow this  

Copy Texture rect into another one

This topic is 4984 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 want to lock a portion of the bigger texture and copy it into another one. here's the code :
		D3DLOCKED_RECT destRect;

		hr = source->LockRect( 0, &srcRect, &lockRect, D3DLOCK_READONLY);
		if( FAILED(hr) )	{
		hr = dest->LockRect( 0, &destRect, null, 0 );
		if( FAILED(hr) )	{

			byte* srcPtr = (byte*)srcRect.pBits;
			byte* destPtr = (byte*)destRect.pBits;

			int numBytesPerPixel = _depth / 8;
			int lineSize = numBytesPerPixel * _width;

			// copy locked rect from source to destination
			for( int i = 0; i < _height; i++ )	{
				memcpy( destPtr, srcPtr, lineSize );

				srcPtr += srcRect.Pitch;
				destPtr += destRect.Pitch;

		source->UnlockRect( 0 );
		dest->UnlockRect( 0 );

when I copy lockRect(0,0,64,64) from the source, it goes fine, but when I want to copy lockRect(64,0,128,64), it goes messed up, and looks like the image is skewed. anyone knows how can I fix this ? thanks

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!