| 130 | } |
| 131 | |
| 132 | bool CopyBitmapToTexture(IDirect3DTexture9* pTexture, Gdiplus::Bitmap& bitmap, UINT width, UINT height) { |
| 133 | using namespace Gdiplus; |
| 134 | |
| 135 | BitmapData bitmapData; |
| 136 | D3DLOCKED_RECT lockedRect; |
| 137 | |
| 138 | if (FAILED(pTexture->LockRect(0, &lockedRect, 0, 0))) { |
| 139 | return false; |
| 140 | } |
| 141 | |
| 142 | if (Rect rect(0, 0, width, height); Ok != bitmap.LockBits(&rect, ImageLockModeRead, PixelFormat32bppARGB, &bitmapData)) { |
| 143 | pTexture->UnlockRect(0); |
| 144 | return false; |
| 145 | } |
| 146 | |
| 147 | auto pSourcePixels = static_cast<unsigned char*>(bitmapData.Scan0); |
| 148 | auto pDestPixels = static_cast<unsigned char*>(lockedRect.pBits); |
| 149 | |
| 150 | for (unsigned int y = 0; y < height; ++y) { |
| 151 | memcpy(pDestPixels, pSourcePixels, width * 4); |
| 152 | pSourcePixels += bitmapData.Stride; |
| 153 | pDestPixels += lockedRect.Pitch; |
| 154 | } |
| 155 | |
| 156 | bitmap.UnlockBits(&bitmapData); |
| 157 | pTexture->UnlockRect(0); |
| 158 | |
| 159 | return true; |
| 160 | } |
| 161 | |
| 162 | /// <summary> |
| 163 | /// Generate a texture to later be used to override a texture. |