I am using std::unique_ptr<uint8[]> CPPPixelBuffer;
to store pixel data of a texture as an array.
This array is initialized in the constructor as followed:
SIZE_T BufferSize = WorldTextureWidth * WorldTextureHeight * DYNAMIC_TEXTURE_BYTES_PER_PIXEL;
CPPPixelBuffer = std::make_unique<uint8[]>(BufferSize);
The creation and drawing of the texture is working so far. (as shown on the picture below) TextureData as the are supposed to be
Now I am trying to create a copy of that array using a for loop. (I am using a for loop because I want to extract just parts of the texture later on. But just for demonstration I copy the array completly in this example.)
SIZE_T PartBufferSize = WorldTextureWidth * WorldTextureHeight * DYNAMIC_TEXTURE_BYTES_PER_PIXEL;
std::shared_ptr<uint8[]> PartPixelBuffer(new uint8[PartBufferSize]());
// Get the base pointer of the pixel buffer
uint8* Ptr = CPPPixelBuffer.get();
//Get the base pointer to the new pixel buffer
uint8* PartPtr = PartPixelBuffer.get();
for (int i = 0; i < WorldTextureHeight *WorldTextureWidth * DYNAMIC_TEXTURE_BYTES_PER_PIXEL; i++) {
*(PartPtr++) = *(Ptr++);
}
delete Ptr;
delete PartPtr;
The pixels after copying are mixed up and the picture is different every time I execute this code. (as shown on the picture below) Wrong Reults
What am I doing wrong?