Texture From GDI Bitmap Object
Is there an easy way to create a direct3d texture object from an in-memory gdi+ bitmap? I can't see a D3DX helper function for it. Failing that, is there an easy way to directly set pixels on a direct3d texture?
Thanks
I found this snippet of code which looks good. Quick question though... does the pitch represent the number of bytes in a row of the returned rectangle?
Thanks
Thanks
LPDIRECT3DTEXTURE9 texture;......D3DXCreateTextureFromFileEx(.., 0, D3DFMT_L8, D3DPOOL_SCRATCH, .., &texture ); ......D3DLOCKED_RECT data;HRESULT hr;hr = texture->LockRect( 0, &data, NULL, D3DLOCK_READONLY ); if (FAILED(hr)){ // error handling goes here // (locking something in the scratch pool // usually shouldn't fail anyway)}......// now have access to the raw data in the texture surface....// cast the void pointer to the size of one of our D3DFMT_L8 pixels// so that the compiler knows the size of an item of data// this allows us to do pointer arithmetic on the surfaceBYTE* bits = (BYTE *)data.pBits;...// access the pixel at x=10, y=20:int offset = ((data.Pitch/sizeof(BYTE)) * 20) + 10;BYTE pixel = bits[offset];...texture->UnlockRect( 0 );
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement