Overloads
static TextureBuilder CreateRenderTarget ()

Returns

TypeDescription
TextureBuilder The texture builder to help build the render target.
edited one year ago#1
finger
Member
JoinedJul 2022 Posts4 Score2,826
Here's a simple implementation of a viewport using this, inheriting from Image:
using Sandbox;
using Sandbox.UI;

/// <summary>
/// A box that will display what a Camera sees.
/// </summary>
public partial class ViewPort : Image
{
    /// <summary>The camera that will render to our texture.</summary>
    public CameraComponent Camera { get; set; }

    /// <summary>The image format that the texture will use.</summary>
    public ImageFormat TextureFormat { get; set; } = ImageFormat.RGBA8888;

    protected override void OnAfterTreeRender( bool firstTime )
    {
        Vector2 textureSize = (Box.Rect.Size.Length != 0) ? Box.Rect.Size : new( 200, 200 );
        Camera.RenderTarget = Texture.CreateRenderTarget( "camerapanel", TextureFormat, textureSize, Camera.RenderTarget );
        Texture = Camera.RenderTarget;
    }

    protected override int BuildHash() => Box.Rect.Size.LengthSquared.FloorToInt();
}

You can then implement it inside a Razor PanelComponent like this:
<ViewPort [email protected] />
finger
Member
JoinedAug 2024 Posts2 Score475
MichaelI need yuou....
Anthony
Member
JoinedAug 2022 Posts3 Score345
people
Log in to reply
You can't reply if you're not logged in. That would be crazy.