In constructor:
RenderTexture = Cast<UTextureRenderTarget2D>(StaticConstructObject(UTextureRenderTarget2D::StaticClass()));
RenderTexture->ClearColor = FLinearColor::Black;
RenderTexture->InitAutoFormat(128.0f, 128.0f);
RenderTexture->UpdateResourceImmediate();
TextureResource = (FTextureRenderTarget2DResource*)RenderTexture->Resource;
if (TextureResource == NULL)
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Green, FString::Printf(TEXT("No resource")));
Canvas = new FCanvas(TextureResource, NULL, GetWorld(), ERHIFeatureLevel::SM5);
Canvas->SetAllowedModes(FCanvas::ECanvasAllowModes::Allow_Flush);
Canvas->Clear(FLinearColor::Black);
In some method:
FCanvasBoxItem box(FVector2D(0.0f, 0.0f), FVector2D(100.0f, 100.0f));
box.SetColor(FLinearColor::Red);
FCanvasLineItem lined(FVector2D(0.0f, 0.0f), FVector2D(100.0f, 100.0f));
lined.LineThickness = 20.0f;
Canvas->DrawItem(box);
Canvas->DrawItem(lined);
Canvas->Flush_GameThread();
If I’m using anything but ERHIFeatureLevel::SM5, game crashing on Flush_GameThread().
UE 4.5 preview.