How to create a texture from image bits?

Started by
2 comments, last by kimryo 21 years, 1 month ago
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.
God create the world,we create another one.-Reference
Advertisement
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.
God create the world,we create another one.-Reference

This topic is closed to new replies.

Advertisement