How to create a texture from image bits?
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.
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 ...
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 ...
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement