Sign in to follow this  

How to create texture from a memory buffer?

This topic is 4482 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, the texture generation functions I have found in the Direct3D SDK either create a texture from a file or some kind of resource, I wonder whether I can create a texture with my own buffer, e.g, that contains the rgb data of an image. Thanks very much!!!

Share this post


Link to post
Share on other sites
Seems like you've got two options:
If feasible, you might be able to use the D3DXCreateTextureFromFileInMemory functions. Have a read over them in the SDK and see if they work for what you want.

If not, you'll probably want to just create the texture using D3DXCreateTexture and then call LockRect() on the texture and copy your own image data in pixel for pixel. This way can get a bit ugly if you also want to use the texture as say a rendertarget or a D3DPOOL_DEFAULT (vidmem) texture, because you'll have to create a texture in system memory pool, lock it and fill it in then create another texture in default pool and use IDirect3DDevice::UpdateTexture to copy the system memory texture into the video card memory texture.

If you don't really need the texture in video memory, just make it managed or dynamic pool as appropriate.

Share this post


Link to post
Share on other sites
Look into the GetSurfaceLevel method of textures and the D3DXLoadSurfaceFromMemory function. There are actually 4 of these threads on the second page of the DX forum [wink]

Share this post


Link to post
Share on other sites

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