> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/gum/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/gum/code/standard-visuals/spriteruntime/rendertargettexturesource.md).

# RenderTargetTextureSource

## Introduction

The RenderTargetTextureSource property allows a Sprite to render a texture produced by a different ContainerRuntime which is drawing to a render target. This feature allows a render target to be scaled, rotated, positioned, stacked, or to use any other Gum layout functionality.

{% hint style="info" %}
To set up this same pattern in the Gum tool, see [Rotating and Scaling Clipped Contents](/gum/gum-tool/tutorials-and-examples/examples/rotating-and-scaling-clipped-contents.md).
{% endhint %}

## RenderTargetTextureSource Requirements

To use RenderTargetTextureSource, the following must exist:

1. A container which has its IsRenderTarget set to true. This container can contain any number of children.
2. A Sprite which has its RenderTargetTextureSource set to the container

{% hint style="info" %}
Normally invisible objects are not rendered and do not perform their Layout calls. If a container has its IsRenderTarget set to true, then it will perform layout and rendering calls so even if invisible so that SpriteRuntime instances can reference the resulting texture.
{% endhint %}

## Code Example: Scaling a ListBox

The following code creates a ListBox which is displayed on a render target with wavy scaling:

```csharp
SpriteRuntime sprite;

protected override void Initialize()
{
    GumUI.Initialize(this);

    var container = new ContainerRuntime();
    container.AddToRoot();
    container.Name = "Render target container";
    container.IsRenderTarget = true;
    container.Dock(Dock.SizeToChildren);
    container.Visible = false;

    var listBox = new ListBox();
    container.AddChild(listBox);
    for (int i = 0; i < 20; i++)
    {
        listBox.Items.Add($"Item {i}");
    }

    sprite = new SpriteRuntime();
    sprite.AddToRoot();
    sprite.Anchor(Anchor.Center);
    sprite.RenderTargetTextureSource = container;

    base.Initialize();
}

protected override void Update(GameTime gameTime)
{
    var gameSeconds = (float)gameTime.TotalGameTime.TotalSeconds;
    sprite.Width = 100 + 50 * MathF.Sin(gameSeconds * 4);
    sprite.Height = 100 + 50 * MathF.Sin(gameSeconds * 3);

    GumUI.Update(gameTime);

    base.Update(gameTime);
}

```

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-5d8dd59bfe6e443f1b8065577e136a10b16ddac8%2F11_05%2056%2052.gif?alt=media" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Currently the ListBox is not interactive because the original ListBox is invisible so it does not receive events from the Cursor. Future versions of Gum may provide a way to interact with invisible controls rendered to a RenderTarget.

This limitation applies to Gum's own `IsRenderTarget` baking. If you instead draw a subtree into a `RenderTarget2D` yourself (for example with `GumBatch`), you can keep it interactive by mapping the cursor with [`HitTestTransformMatrix`](/gum/code/events-and-interactivity/mouse-and-touch-screen-cursor.md#several-coordinate-spaces-at-once-hittesttransformmatrix).
{% endhint %}

If you are managing a render target yourself instead of using `IsRenderTarget`, see [Render Targets](/gum/code/rendering/render-targets.md) for the blend-mode setup needed to composite translucent content correctly on MonoGame and raylib.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.flatredball.com/gum/code/standard-visuals/spriteruntime/rendertargettexturesource.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
