Jump to content
  • Advertisement
Sign in to follow this  
Jazonxyz

Creating a texture from memory

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

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!