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()
{
	Super::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;
	Canvas->DrawItem(TileItem);



	// 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;
	Canvas->DrawItem(TileItem2);
}

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.

Hi,

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;

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.

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

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!

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 :frowning:

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