Sign in to follow this  
Jazonxyz

Creating a texture from memory

Recommended Posts

I was wondering if its possible to create a texture from a BITMAP. is there something like this: ex BITMAP bm; LPDIRECT3DTEXTURE9 = CreateFromMemory(&bm,blah,blah,blah...); Thank you in advance.

Share this post


Link to post
Share on other sites
I don't know much DX but from looking at MSDN D3DXCreateTextureFromFileInMemory() might be what you want.

Edit:

Ok reading it over maybe not. D3DXCreateTextureFromFileInMemory() loads from a image file thats been put into memory, not from a chunk of pixel data in memory. I think what you want is to create your texture then Lock() it to get a pointer to the bytes then copy the bitmap data in (Theres a member of BITMAP that has the pixel data I think?) then Unlock() it.

Share this post


Link to post
Share on other sites
D3DXCreateTexture
D3DXCreateTextureFromFile
D3DXCreateTextureFromFileEx
D3DXCreateTextureFromFileInMemory <= set pSrcData as the pointer to the file memory of bitmap
D3DXCreateTextureFromFileInMemoryEx
D3DXCreateTextureFromResource
D3DXCreateTextureFromResourceEx

Share this post


Link to post
Share on other sites
A BITMAP isn't usually an image, it's just the header for it. Where are you getting this data from?

Working example:

void* pData; // Pointer to the file data as loaded into memory
UINT nLen; // Length of the source data in bytes

// Load the file into the buffer above in whatever way

LPDIRECT3DTEXTURE9 pTexture; // Output texture
D3DXCreateTextureFromFileInMemory(pDevice, pData, nLen, &pTexture);


Share this post


Link to post
Share on other sites
If you have raw data rather than a file in memory then D3DXLoadSurfaceFromMemory() is probably the function you want to use. To use it first create a texture with IDirect3DDevice9::CreateTexture() and then use IDirect3DTexture9::GetSurfaceLevel() to get at each mipmap surface for loading into.

You can retrieve that raw data from a HBITMAP with the standard Windows GetDIBits() function.

Share this post


Link to post
Share on other sites

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