I have a pointer to loacation in memory which contains my pixel information. I want to display this on screen using textures or any other form.Is it possible to create texture from memory in directx 9? Thanks
Here is the code sample
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 by drawing rectangle primitive Here before setTexture if i save my texture to a BMP file by D3DXSaveTextureToFile() and then create texture using D3DXCreateTextureFromFile(). Then i get expected output