LPDIRECT3DTEXTURE9 Menu::steam_image(IDirect3DDevice9* device)
{
int iImage = SteamFriends->GetLargeFriendAvatar(SteamUser->GetSteamID());
if (iImage == -1)
return nullptr;
uint32 uAvatarWidth, uAvatarHeight;
if (!SteamUtils->GetImageSize(iImage, &uAvatarWidth, &uAvatarHeight))
return nullptr;
const int uImageSizeInBytes = uAvatarWidth * uAvatarHeight * 4;
uint8* pAvatarRGBA = new uint8[uImageSizeInBytes];
if (!SteamUtils->GetImageRGBA(iImage, pAvatarRGBA, uImageSizeInBytes))
{
delete[] pAvatarRGBA;
return nullptr;
}
auto res = device->CreateTexture(uAvatarWidth,
uAvatarHeight,
1,
D3DUSAGE_DYNAMIC,
D3DFMT_A8R8G8B8,
D3DPOOL_DEFAULT,
&texture,
nullptr);
std::vector<uint8_t> texData;
texData.resize(uAvatarWidth * uAvatarHeight * 4u);
CopyConvert(pAvatarRGBA,
texData.data(),
uAvatarWidth * uAvatarHeight * 4u);
D3DLOCKED_RECT rect;
res = texture->LockRect(0, &rect, nullptr, D3DLOCK_DISCARD);
auto src = texData.data();
auto dst = reinterpret_cast<uint8_t*>(rect.pBits);
for (auto y = 0u; y < uAvatarHeight; ++y)
{
std::copy(src, src + (uAvatarWidth * 4), dst);
src += uAvatarWidth * 4;
dst += rect.Pitch;
}
res = texture->UnlockRect(0);
delete[] pAvatarRGBA;
return texture;
}