compiling error (need help)

Started by
1 comment, last by Blodyavenger 13 years, 11 months ago
I have this function to read pixel value from texture but I get compiling error at line
const BYTE* pBits = rect.pBits;

The error says:
error C2440: 'initializing' : cannot convert from 'void *' to 'const BYTE'

D3DCOLOR readPixel(LPDIRECT3DTEXTURE9 pTexture, UINT x, UINT y){   // Lock the texture:   D3DLOCKED_RECT rect;   HRESULT hResult = pTexture->LockRect(0, &rect, NULL, D3DLOCK_READONLY);   if(FAILED(hResult))   {      // Failed to lock the texture, error      return 0;   }   // Get the bits as a BYTE*   const BYTE* pBits = rect.pBits;   // Seek to the correct pixel and read it   DWORD nBytesPerPixel = 4;   const DWORD* pPixel = (DWORD*)(pBits + y * rect.Pitch + x*nBytesPerPixel);   DWORD dwPixel = *pPixel;   // Unlock the texture   pTexture->UnlockRect(0);   // Return the pixel   return dwPixel;}
Advertisement

Change it to const BYTE *pBits = (BYTE *) rect.pBits;
It's working, thanks a lot! :)

This topic is closed to new replies.

Advertisement