How to create texture from a memory buffer?

Started by
3 comments, last by Charlie Lau 18 years, 7 months ago
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!!!
Advertisement
关注
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.
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]
Thank you guys very much:-)

This topic is closed to new replies.

Advertisement