Sign in to follow this  

Copy Texture rect into another one

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

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