Creating a texture from memory

Started by
6 comments, last by Adam_42 15 years, 7 months ago
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.
Advertisement
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.
D3DXCreateTexture
D3DXCreateTextureFromFile
D3DXCreateTextureFromFileEx
D3DXCreateTextureFromFileInMemory <= set pSrcData as the pointer to the file memory of bitmap
D3DXCreateTextureFromFileInMemoryEx
D3DXCreateTextureFromResource
D3DXCreateTextureFromResourceEx
akira32 編程之家 Yahoohttp://tw.myblog.yahoo.com/akira32-akira32
OK, thanks
Can someone give me a working example?
Anybody?
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 memoryUINT nLen; // Length of the source data in bytes// Load the file into the buffer above in whatever wayLPDIRECT3DTEXTURE9 pTexture; // Output textureD3DXCreateTextureFromFileInMemory(pDevice, pData, nLen, &pTexture);
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.

This topic is closed to new replies.

Advertisement