x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

My UCanvasRenderTarget object only draws black shapes

I'm trying to use a UCanvasRenderTarget to draw some shapes into a texture that is a applied to a material, assigned to a simple plane mesh. It kinda works, except that everything I draw is always pitch black, like this:

alt text

(the blue color is just the "clear color" I'm using for the render target).

This is what the code looks like:

 void UMyObject::BeginPlay()
 {
     Super::BeginPlay();

     // Creating my render target and binding the function that is called on draw
     mCanvasRenderTarget = Cast<UCanvasRenderTarget2D>(UCanvasRenderTarget2D::CreateCanvasRenderTarget2D(mOwner, UCanvasRenderTarget2D::StaticClass(), 4096, 4096));
     mCanvasRenderTarget->OnCanvasRenderTargetUpdate.AddDynamic(this, &UMyObject::DrawToCanvasRenderTarget);

     mCanvasRenderTarget->ClearColor = FLinearColor::Blue;

     // Forcing it to draw
     mCanvasRenderTarget->UpdateResource();

     // Skipping the part where I assing the render target to a material...
 }


 void UMyObject::DrawToCanvasRenderTarget(UCanvas* Canvas, int32 Width, int32 Height)
 {
     // My "blue" rectangle, which is black
     FCanvasTileItem BlueBox(FVector2D(Width * 0.3f, Height * 0.3f), mCanvasRenderTarget->Resource, FVector2D(Width * 0.4f, Height * 0.4f), FLinearColor(0.0f, 0.0f, 1.0f));
     Canvas->DrawItem(BlueBox);
 }

Even if I add "Canvas->SetDrawColor = FColor::Blue" before the DrawItem call, the rectangle is still black... what am I missing?

Product Version: UE 4.19
Tags:
render.png (286.6 kB)
more ▼

asked Apr 13 '18 at 10:08 AM in Rendering

avatar image

Beriol
58 4 8 16

(comments are locked)
10|2000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question