Hi,
I had a a D3DFMT_A16B16G16R16 format texture I want to read. I did sth like this:
float *dest = new float[size*size*4];
D3DLOCKED_RECT locked;
HRESULT hr = ptex->LockRect(0, &locked, NULL, 0);
assert(hr == S_OK);
WORD *fPointer=(WORD *)locked.pBits; for (DWORD y=0; y<size; y++){
for (DWORD x=0; x<size; x++){
DWORD index=( x*4 + (y*(locked.Pitch/2)));
dest[y*size*4+x*4] = fPointer[index] ;
dest[y*size*4+x*4+1] = fPointer[index+1] ;
dest[y*size*4+x*4+2] = fPointer[index+2] ;
dest[y*size*4+x*4+3] = fPointer[index+3] ;
}
}
ptex->UnlockRect(0);
But it seems not working, does anyone know how to do it Thanks a lot,
Jianfeng

How to read a D3DFMT_A16B16G16R16 texture?
Craver84
This should work, but looks unusual. Each component in a D3DFMT_A16B16G16R16 pixel is a 16-bit unsigned value ranging from 0 to 65535. When you convert this value to a float, the value remains the same. If you're expecting your float array to have values in the range of 0.0 to 1.0 then you need to divide by 65535.0:
Alternatively, your problem might instead be that you're trying to read a D3DFMT_A16B16G16R16F format texture, where each component is a 16-bit floating point value. In that case you'ld need to use D3DXFloat16To32Array() to convert the values.
Marcel de Vries