Create textures from directx memory

I have a pointer to loacation in memory that contains my pixel information. I want to display this on the screen using textures or any other shape. Is it possible to create a texture from memory in directx 9? Thanks

Here is a sample code

D3DLOCKED_RECT r; HRESULT hr; DWORD c0=D3DCOLOR_ARGB(255,0,0,0), c1=D3DCOLOR_ARGB(255,255,255,255); DWORD *pData, Image[64]={c0,c0,c0,c1,c0,c0,c0,c0, c0,c0,c0,c1,c0,c0,c0,c0, c0,c0,c0,c1,c0,c0,c0,c0, c1,c1,c1,c1,c1,c1,c1,c0, c0,c0,c0,c1,c0,c0,c0,c0, c0,c0,c0,c1,c0,c0,c0,c0, c0,c0,c0,c1,c0,c0,c0,c0, c0,c0,c0,c0,c0,c0,c0,c0}; if (m_pDevice->CreateTexture(8,8,1,D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_pPointTexture,NULL)!=D3D_OK) return false; if (m_pPointTexture->LockRect(0,&r,NULL, D3DLOCK_DISCARD |D3DLOCK_NOOVERWRITE)!=D3D_OK) return false; for (int y=0; y<8; y++) { pData=(DWORD*)((BYTE*)r.pBits + r.Pitch); for (int x=0; x<8; x++) pData[x]=Image[y*8+x]; } m_pDevice->SetTexture(0,m_pPointTexture); 

Then in I render it, drawing the rectangle primitive Here before setTexture, if I save my texture in a BMP file using D3DXSaveTextureToFile (), and then create a texture using D3DXCreateTextureFromFile (). Then I get the expected result

+4
source share
1 answer

D3DXCreateTextureFromFileInMemory ( doc ) if it is an image file in memory.

However, if only the color data just creates a texture with D3DXCreateTexture ( doc ), lock it and write the data to the texture manually.

+4
source

All Articles