Archived

This topic is now archived and is closed to further replies.

kimryo

How to create a texture from image bits?

Recommended Posts

My code as follow: D3DXCreateTexture(pDevice,128,128,D3DX_DEFAULT,0,D3DFMT_X8R8G8B8,D3DPOOL_MANAGED,&m_p); D3DLOCKED_RECT DataRect; m_p->LockRect(0,&DataRect,NULL,0); memcpy(DataRect.pBits,pImageBit,DataRect.Pitch*128); m_p->UnlockRect(0); But I got a memory access violation...why? thanks. We create world.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Be sure pImageBit is big enough for the copy operation for one, second make sure you are not going out of bounds with DataRect.Pitch*128 ...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Be sure pImageBit is big enough for the copy operation for one, second make sure you are not going out of bounds with DataRect.Pitch*128 ...

Share this post


Link to post
Share on other sites
Well.The copy code change to:

memcpy(DataRect.pBits,pImageBit,128*128);//pImageBits is 128*128,and DataRect.Pitch=512.


This will successfully create that texture,but when invoke IDirect3DDevice::SetTexutre,the error come:

Direct3D9: (ERROR) :Invalid texture pointer. SetTexture failed.

How to fix?thanks.

We create world.

Share this post


Link to post
Share on other sites