Table of Contents

Class Texture

Namespace
LibGFX.Graphics
Assembly
LibGFX.dll

Represents a texture that can be used in rendering.

public class Texture : IGraphicsResource, ISerialization, IIdentifier
Inheritance
Texture
Implements
Inherited Members

Constructors

Texture()

Initializes a new instance of the Texture class with default values.

public Texture()

Texture(int, int, Vector4i)

Initializes a new instance of the Texture class with specified width, height, and solid color.

public Texture(int widt, int height, Vector4i color)

Parameters

widt int
height int
color Vector4i

Texture(int, int, byte[])

Initializes a new instance of the Texture class with specified width, height, and raw pixel data in RGBA format.

public Texture(int width, int height, byte[] pixeldata)

Parameters

width int
height int
pixeldata byte[]

Exceptions

ArgumentException

Texture(string)

Initializes a new instance of the Texture class by loading texture data from a file path.

public Texture(string path)

Parameters

path string

Fields

DefaultUVScale

The default UV scale for a texture. Value: (1.0, 1.0)

public static readonly Vector2 DefaultUVScale

Field Value

Vector2

DefaultUVTransform

The default UV transform for a texture. Scale: (1.0, 1.0), Offset: (0.0, 0.0)

public static readonly Vector4 DefaultUVTransform

Field Value

Vector4

Properties

HasAlpha

Gets or sets a value indicating whether the image contains an alpha (transparency) channel.

public bool HasAlpha { get; set; }

Property Value

bool

Height

The height of the texture in pixels.

public int Height { get; set; }

Property Value

int

ID

Gets the unique identifier for this instance.

public Guid ID { get; }

Property Value

Guid

IsInitialized

Gets a value indicating whether the object has been initialized.

public bool IsInitialized { get; }

Property Value

bool

Name

public string Name { get; set; }

Property Value

string

TextureData

The raw texture data in RGBA format.

public byte[]? TextureData { get; set; }

Property Value

byte[]

TextureId

The unique identifier for the texture.

public int TextureId { get; set; }

Property Value

int

TextureParameters

Gets or sets the parameters used to configure texture sampling and filtering. Must be set before initializing the texture with a render device.

public TextureParameters TextureParameters { get; set; }

Property Value

TextureParameters

Width

The width of the texture in pixels.

public int Width { get; set; }

Property Value

int

Methods

Copy()

Creates a copy of the texture.

public Texture Copy()

Returns

Texture

Deserialize(JObject, SerializationContext, Func<JObject, bool>)

Constructs the texture from JSON data.

public void Deserialize(JObject obj, SerializationContext context, Func<JObject, bool> callback = null)

Parameters

obj JObject
context SerializationContext
callback Func<JObject, bool>

Exceptions

InvalidOperationException
JsonException

Dispose(IRenderDevice)

Frees resources used by the texture within the gpu.

public void Dispose(IRenderDevice renderer)

Parameters

renderer IRenderDevice

FreeCPUResources()

Frees the CPU resources used by the texture.

public void FreeCPUResources()

GetSafeUVTransform(float, float, float, float)

Get a safe UV transform for a given area of the texture, avoiding edge artifacts. Used for tilemaps and similar scenarios where you want to avoid sampling the edges of the texture.

public Vector4 GetSafeUVTransform(float x, float y, float width, float height)

Parameters

x float
y float
width float
height float

Returns

Vector4

GetSubImage(Rect)

Get the UV transform for a given area of the texture.

public Vector4 GetSubImage(Rect area)

Parameters

area Rect

Returns

Vector4

GetSubImage(float, float, float, float)

Gets the sub-image UV transforms for a specified area of the texture.

public Vector4 GetSubImage(float x, float y, float width, float height)

Parameters

x float
y float
width float
height float

Returns

Vector4

Init(IRenderDevice)

Initializes the texture with the specified render device.

public void Init(IRenderDevice renderer)

Parameters

renderer IRenderDevice

MirrorUVTransform(Vector4, TextureMirrorMode)

Mirror the UV transform based on the specified mirror mode.

public static Vector4 MirrorUVTransform(Vector4 uvTransform, TextureMirrorMode mode)

Parameters

uvTransform Vector4
mode TextureMirrorMode

Returns

Vector4

Serialize(JsonWriter, SerializationContext, Action<JsonWriter>)

Serializes the texture to JSON.

public void Serialize(JsonWriter writer, SerializationContext context, Action<JsonWriter> callback = null)

Parameters

writer JsonWriter
context SerializationContext
callback Action<JsonWriter>

ToBitmap()

Convert the texture data to a Bitmap.

public Bitmap ToBitmap()

Returns

Bitmap

Exceptions

InvalidOperationException