MCPcopy Create free account
hub / github.com/Lovrom8/RSMods / CopyBitmapToTexture

Function CopyBitmapToTexture

DLL/D3D/D3D.cpp:132–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

130}
131
132bool 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.

Callers 1

GenerateTextureMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected