• Advertisement
Sign in to follow this  

Copy one texture to another

This topic is 4415 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 have this code
      destinoSF = NULL;


   // Get textures
   // fuenteTX holds the source texture
   // destinoTX holds the final texture

   fuenteTX->GetSurfaceLevel (0, &fuenteSF);
   destinoTX->GetSurfaceLevel (0, &destinoSF);

   // The RECTs are used to copy all the source texture to the final texture
   fuenteSF->GetDesc (&info);
   RECT fuenteRT = {0, 0, info.Width, info.Height};

   destinoSF->GetDesc (&info);
   RECT destinoRT = {0, 0, info.Width, info.Height};

   D3DXLoadSurfaceFromSurface (
      destinoSF, NULL, &destinoRT,
      fuenteSF, NULL, &fuenteRT,

   fuenteSF->Release ();
   destinoSF->Release ();
This copy the top-level surface of one texture to another, but the result is very odd, when i draw the texture (over polygons) the closer i am to them, it shows the final texture, is OK!, but when i get away from them it starts to fade to the source texture until the source texture is shown completly, im missing something ? i can upload some screenshots if you dont understand what i mean thanks in advance

Share this post

Link to post
Share on other sites
Upon changing a texture's surface, the MIP maps are not modified along with the largest surface of the texture.

This means you need to tell DX to generate new MIP maps for your textures.

Easiest way is to call ->GenerateMIPMaps() on the texture. I'd recommend you also include the AutoGenMIPMaps flag at texture creation if you're doing this more than once per texture.

Hope this helps.

Share this post

Link to post
Share on other sites
I found a function on

|__ IDirect3DTextyure9

IDirect3DBaseTexture9::GenerateMipSubLevels ()

And used this at the end of the code, but there where no changes at all

The fuction to create the texture is:

D3DXCreateTextureFromFileEx (pDispositivo, pNombreArchivo, D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, pColor, NULL, NULL, &mTextura);

HRESULT D3DXCreateTextureFromFileEx(
UINT Width,
UINT Height,
UINT MipLevels,
DWORD Usage,
DWORD Filter,
DWORD MipFilter,
D3DCOLOR ColorKey,

But the usage only accepts 0, D3DUSAGE_RENDERTARGET, or D3DUSAGE_DYNAMIC according to the documentation, if I put D3DUSAGE_AUTOGENMIPMAP on Usage, no texture is show at all :(

As you can see, i managed to correct the odd behavior by using only 1 mipmap level (the top one), but i still want to use mipmap lvls

Some one can give me some advice about this ? i cant find even a clue

Share this post

Link to post
Share on other sites
You could always copy the mip levels manually, just like you process the top-level surface.

Autogen mipmaps are, as far as I know, designed for render target textures. I haven't used the feature on static textures, as there's little point in doing that. However, you should be able to do so if you want.

The texture that you want to use automatic mipmap generation with must be in video memory - that is, D3DPOOL_DEFAULT - since it's the hardware's responsibility to update the mip levels if the feature is supported by it in the first place.

Share this post

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

  • Advertisement