I’m trying to create a texture at runtime and draw it in my Canvas, I’ve been trying to get it work all day with now without any success at all!
Texture is defined as class UTexture2D *Texture
with a UPROPERTY in my HUD header
// Consts
const FColor ColorOne = FColor(0, 255, 0);
const FColor ColorTwo = FColor(255, 0, 0);
const int32 CheckerSize = 512;
const int32 HalfPixelNum = CheckerSize >> 1;
// Create the texture
Texture = UTexture2D::CreateTransient(CheckerSize, CheckerSize, PF_B8G8R8A8);
// Lock the checkerboard texture so it can be modified
FColor* MipData = static_cast<FColor*>(Texture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE));
// Fill in the colors in a checkerboard pattern
for (int32 RowNum = 0; RowNum < CheckerSize; ++RowNum)
{
for (int32 ColNum = 0; ColNum < CheckerSize; ++ColNum)
{
FColor& CurColor = MipData[(ColNum + (RowNum * CheckerSize))];
if (ColNum < HalfPixelNum)
{
CurColor = ColorOne;
}
else
{
CurColor = ColorTwo;
}
}
}
// Unlock the texture
Texture->PlatformData->Mips[0].BulkData.Unlock();
Texture->UpdateResource();
However, when I get to DrawHUD and try to print this texture, it looks nothing like the thing I’m looking for (the format is BGRA, so left side blue, right side green).
Canvas->DrawTile(Texture, 0, 0, 1, 512, 512, 0, 0, 1, 1);
Can someone enlighten me what I’m doing wrong, cause it’s driving me insane! I also tried the Memcpy
and ENQUEUE_UNIQUE_RENDER_COMMAND_TWOPARAMETER
approaches, NOTHING WORKS! D: