4

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

1 Answer 1

5

D3DXCreateTextureFromFileInMemory (doc) if it's a imagefile in memory.

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

Sign up to request clarification or add additional context in comments.

9 Comments

I tried doing it but the result is displayed as blank black screen where as wen i write my created texture to bmp file using D3DXSaveTextureToFile() and then load the created BMP into texture using D3DXCreateTextureFromFile() i get the expected output.. Any idea where im going wrong
Can you add some code of your loading and rendering to your question?
D3DLOCK_NOOVERWRITE can only be used for vertexbuffers not for textures. D3DLOCK_DISCARD is sufficient. And you have to unlock the texture with UnlockRect. Apart from that I don't see other problems.
oh yea.. i have used unlockRect also forgot to mention that..Now changed to D3DLOCK_DISCARD also but still same problem..
If you could give me an example of how to create/render texture from memory that would be a great help to me.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.