Sign in to follow this  
buddycopper

Copying textures

Recommended Posts

Hi, I'm confused. How do you copy a IDirect3DTexture9 to another IDirect3DTexture9? For example, I create two textures: IDirect3DTexture9 *srcText; IDirect3DTexture9 *destText; I then load a bitmap into srcText with D3DXCreateTextureFromFile. Now I want to copy the contents of srcText to destText. This is what I was trying to do: // Copy texture destText = srcText; // Release source texture srcText->Release(); I know the problem is that I'm copying pointers and not the actual data, but how would I copy the actual data? Doing *destText = *srcText; causes the texture to be blank. Thanks, Brian

Share this post


Link to post
Share on other sites
I think you need to use the texture function LockRect(), to get access to the pixel data of the texture, and then use D3DXLoadSurfaceFromMemory() to copy that data to a surface.

So, step by step, you would do the following:

1. Use D3DXCreateTextureFromFile() to create the source texture.

2. Use D3DXCreateTexture() to create the destination texture (assuming it isn't already created).

3. Call srcText->LockRect() to get access to the pixel data.

4. Call destText->GetSurfaceLevel() to get the primary surface of the texture.

5. Use D3DXLoadSurfaceFromMemory() to copy all the data from the pixel data source to the destination surface.

6. Call destSurf->Release() to release your reference to the surface.

7. Call srcText->UnlockRect() to unlock the source texture.

It's a bit of work, but I don't know of any other way to do it. What specifically are you trying to accomplish, by the way?

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