ImageTexture

A Texture based on an Image.

For an image to be displayed, an ImageTexture has to be created from it using the createFromImage method:

More...

Members

Aliases

BaseClasses
alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses)
Undocumented in source.

Enums

Constants
enum Constants
Storage
enum Storage

Functions

_reloadHook
void _reloadHook(RID rid)
create
void create(long width, long height, long format, long flags)

Create a new ImageTexture with width and height. format is a value from Image.format, flags is any combination of Texture.flags.

createFromImage
void createFromImage(Image image, long flags)

Initializes the texture by allocating and setting the data from an Image with flags from Texture.flags. An sRGB to linear color space conversion can take place, according to Image.format.

getFormat
Image.Format getFormat()

Returns the format of the texture, one of Image.format.

getLossyStorageQuality
double getLossyStorageQuality()
getStorage
ImageTexture.Storage getStorage()
load
GodotError load(String path)

Loads an image from a file path and creates a texture from it. Note: the method is deprecated and will be removed in Godot 4.0, use Image.load and createFromImage instead.

opAssign
typeof(null) opAssign(typeof(null) n)
opEquals
bool opEquals(ImageTexture other)
opEquals
bool opEquals(typeof(null) n)
setData
void setData(Image image)

Replaces the texture's data with a new Image. Note: The texture has to be initialized first with the createFromImage method before it can be updated. The new image dimensions, format, and mipmaps configuration should match the existing texture's image configuration, otherwise it has to be re-created with the createFromImage method. Use this method over createFromImage if you need to update the texture frequently, which is faster than allocating additional memory for a new texture each time.

setLossyStorageQuality
void setLossyStorageQuality(double quality)
setSizeOverride
void setSizeOverride(Vector2 size)

Resizes the texture to the specified dimensions.

setStorage
void setStorage(long mode)
toHash
size_t toHash()

Mixins

__anonymous
mixin baseCasts
Undocumented in source.

Properties

lossyQuality
double lossyQuality [@property getter]
double lossyQuality [@property setter]

The storage quality for constant STORAGE_COMPRESS_LOSSY.

storage
ImageTexture.Storage storage [@property getter]
long storage [@property setter]

The storage type (raw, lossy, or compressed).

Static functions

_new
ImageTexture _new()

Construct a new instance of ImageTexture. Note: use memnew!ImageTexture instead.

Static variables

_classBindingInitialized
bool _classBindingInitialized;
Undocumented in source.

Structs

GDNativeClassBinding
struct GDNativeClassBinding
Undocumented in source.

Unions

__anonymous
union __anonymous
Undocumented in source.

Variables

_GODOT_internal_name
enum string _GODOT_internal_name;
Undocumented in source.

Mixed In Members

From mixin baseCasts

as
inout(To) as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
inout(To) as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
inout(ToRef) as()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(ToRef)
Undocumented in source.
opCast
void* opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
godot_object opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
bool opCast()
Undocumented in source. Be warned that the author may not have intended to support it.

Detailed Description

var texture = ImageTexture.new() var image = Image.new() image.load("res://icon.png") texture.create_from_image(image) $Sprite.texture = texture

This way, textures can be created at run-time by loading images both from within the editor and externally. Warning: Prefer to load imported textures with @GDScript.load over loading them from within the filesystem dynamically with Image.load, as it may not work in exported projects:

var texture = load("res://icon.png") $Sprite.texture = texture

This is because images have to be imported as StreamTexture first to be loaded with @GDScript.load. If you'd still like to load an image file just like any other Resource, import it as an Image resource instead, and then load it normally using the @GDScript.load method. But do note that the image data can still be retrieved from an imported texture as well using the Texture.getData method, which returns a copy of the data:

var texture = load("res://icon.png") var image : Image = texture.get_data()

An ImageTexture is not meant to be operated from within the editor interface directly, and is mostly useful for rendering images on screen dynamically via code. If you need to generate images procedurally from within the editor, consider saving and importing images as custom texture resources implementing a new EditorImportPlugin. Note: The maximum texture size is 16384×16384 pixels due to graphics hardware limitations.

Meta