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"

Render UTextureRenderTarget2D to HUD

Hello (it's my first time here)

I'm trying to render from a SceneCapture2D Camera to the HUD (a minimap). The code I have for the HUD is to draw a crosshair in the middle of the screen. I got that from a tutorial.

I declared my Render Target texture pointer in the header

     UTextureRenderTarget2D* MinimapTex;

And initialized it in the constructor of the HUD class like this:

     static ConstructorHelpers::FObjectFinder<UTextureRenderTarget2D> MinimapTexObj(TEXT("TextureRenderTarget2D'/Game/Textures/MinimapTexture.MinimapTexture'"));
     MinimapTex = MinimapTexObj.Object;

This is how the DrawHUD method looks:

 void AFPSHUD::DrawHUD()
     // Draw very simple crosshair
     // find center of the Canvas
     const FVector2D Center(Canvas->ClipX * 0.5f, Canvas->ClipY * 0.5f);
     // offset by half the texture's dimensions so that the center of the texture aligns with the center of the Canvas
     const FVector2D CrosshairDrawPosition((Center.X - (CrosshairTex->GetSurfaceWidth() * 0.5)),
         (Center.Y - (CrosshairTex->GetSurfaceHeight() * 0.5f)));
     // draw the crosshair
     FCanvasTileItem TileItem(CrosshairDrawPosition, CrosshairTex->Resource, FLinearColor(1.0f, 1.0f, 1.0f, 0.66f));
     TileItem.BlendMode = SE_BLEND_Translucent;
     // Draw Minimap
     const FVector2D MinimapDrawPosition(10.0f, Canvas->ClipY - 10.0f - MinimapTex->GetSurfaceHeight());
     FCanvasTileItem TileItem2(MinimapDrawPosition, MinimapTex->Resource, FLinearColor::White);
     TileItem2.BlendMode = SE_BLEND_Translucent;

The first part draws the crosshair, that works great.

The second part should draw the minimap, but it doesn't. I tried debugging a bit, the size of the TileItem2 seems to be 0. That doesn't look right but I don't know how to solve it.

Product Version: Not Selected
more ▼

asked Sep 27 '14 at 12:46 PM in C++ Programming

avatar image

6 1 2 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first


You can set a size via the tile item itself

 TileItem2.Size = FVector2D(Width, Height);

Also, if you obtained the UTextureRenderTarget2D from an ASceneCapture2D you will either have to set the blend mode to SE_BLEND_Opaque or override the pixel format. Not sure if this has to be done before the capture.

 MinimapTex->OverrideFormat = EPixelFormat::PF_FloatRGB;
more ▼

answered Sep 28 '14 at 02:37 AM

avatar image

46 2 2 4

avatar image wststreet Sep 28 '14 at 09:27 AM

I can't believe I didn't think of trying that. I did try setting the blend to Opaque but not setting the size manually. I guess I'm used to not being allowed to change fields like that.

Thank you.

avatar image folco75 Oct 21 '14 at 06:53 PM

Hi wststreet, i have a similar problem. I need to render from a SceneCapture2D Camera to the HUD. I am trying to "finalize" my draw operation with a AHud->DrawTextureSimple (but i think this is less important). Would you be so kind to share your code with me? Obviously only the part related to SceneCapture2D binding (i hope you are not using blueprints :)) Thanks

avatar image wststreet Oct 21 '14 at 07:12 PM

Hey, I'd be glad to help, but I don't understand exactly what you mean. What I posted is all the code for rendering the camera on the HUD. There's a blueprint to move the camera along with the player. So if that's what you need, sorry to disappoint you but I didn't use code for that :(

avatar image folco75 Oct 21 '14 at 07:25 PM

Ok thanks. My problem is how to make in c++ assignment SceneCapture <-> UTextureRenderTarget2D. In my scenario i cannot use blueprint to do that. Thanks :)

avatar image rynix Oct 21 '14 at 07:30 PM

Hi, I would suggest taking a look at the StrategyGame example. I don't have the code on hand to point you to the exact locations, but you should be able to learn the specifics from their HUD class. Good luck!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
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