Sign in to follow this  

Copying loaded texture data to IDirect3DTexture9 object

This topic is 4036 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'm trying to find out how to create an 'IDirect3DTexture9' object and bascially copy raw texture data that I've loaded myself (seperately) into the texture object. I assume that this is possible since people would need to use more than a single set of textures (.bmp, .dds, .dib, .hdr, .jpg, .pfm, .png, .ppm, and .tga). How do I go about it? I was thinking about creating a texture with 'D3DXCreateTexture' and then finding out how to copy the texture data into the object. I looked into 'D3DXCreateTextureFromFileInMemory', but it looks like it just loads data from a file image in memory, instead of loading raw RGB or RGBA (or ARGB) data. ... Do I have to use something like 'D3DXFillTexture'?

Share this post


Link to post
Share on other sites
The primary method is to lock the texture and directly copy the data in - IDirect3DTexture9::LockRect() for more details. It can get quite fiddly with the conversion and strides (etc..) so you can use D3DXFillTexture() (use the pData param to pass in your data) and let it deal with the finer details...

You can use the D3DXCreateTextureFromFileInMemory() function - generating a bitmap header and then storing all your custom data as RGB24 triplets isn't too hard. It can then do the actual creation/loading of data.

Be careful of mip-mapped textures when manually modifying the textures - unless you have autogen mip-mapping you'll need to modify all mip-levels accordingly.

hth
Jack

Share this post


Link to post
Share on other sites
Keep in mind that textures in the Default pool that are not Dynamic cannot be locked. If you need to write data to those textures, you'll need to place the data in a SysMem surface and then use UpdateTexture. IIRC, UpdateTexture also takes care of the MIP levels for you.

This shouldn't really matter, since for most uses using Managed pool textures provides the best results.

Hope this helps.

Share this post


Link to post
Share on other sites

This topic is 4036 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.

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