Jump to content
  • Advertisement
Sign in to follow this  

Copying textures

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

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
Sign in to follow this  

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