Texture

Inherits: Resource < Reference < Object

Inherited By: AnimatedTexture, AtlasTexture, CameraTexture, CurveTexture, ExternalTexture, GradientTexture, ImageTexture, LargeTexture, MeshTexture, NoiseTexture, ProxyTexture, StreamTexture, ViewportTexture

Texture for 2D and 3D.

Description

A texture works by registering an image in the video hardware, which then can be used in 3D models or 2D Sprite or GUI Control.

Textures are often created by loading them from a file. See @GDScript.load.

Texture is a base for other resources. It cannot be used directly.

Properties

int flags 4

Methods

void draw ( RID canvas_item, Vector2 position, Color modulate=Color( 1, 1, 1, 1 ), bool transpose=false, Texture normal_map=null ) const
void draw_rect ( RID canvas_item, Rect2 rect, bool tile, Color modulate=Color( 1, 1, 1, 1 ), bool transpose=false, Texture normal_map=null ) const
void draw_rect_region ( RID canvas_item, Rect2 rect, Rect2 src_rect, Color modulate=Color( 1, 1, 1, 1 ), bool transpose=false, Texture normal_map=null, bool clip_uv=true ) const
Image get_data ( ) const
int get_height ( ) const
Vector2 get_size ( ) const
int get_width ( ) const
bool has_alpha ( ) const

Enumerations

enum Flags:

  • FLAGS_DEFAULT = 7 — Default flags. FLAG_MIPMAPS, FLAG_REPEAT and FLAG_FILTER are enabled.
  • FLAG_MIPMAPS = 1 — Generates mipmaps, which are smaller versions of the same texture to use when zoomed out, keeping the aspect ratio.
  • FLAG_REPEAT = 2 — Repeats the texture (instead of clamp to edge).
  • FLAG_FILTER = 4 — Uses a magnifying filter, to enable smooth zooming in of the texture.
  • FLAG_ANISOTROPIC_FILTER = 8 — Uses anisotropic mipmap filtering. Generates smaller versions of the same texture with different aspect ratios.

This results in better-looking textures when viewed from oblique angles.

  • FLAG_CONVERT_TO_LINEAR = 16 — Converts the texture to the sRGB color space.
  • FLAG_MIRRORED_REPEAT = 32 — Repeats the texture with alternate sections mirrored.
  • FLAG_VIDEO_SURFACE = 2048 — Texture is a video surface.

Property Descriptions

Default 4
Setter set_flags(value)
Getter get_flags()

The texture’s Flags. Flags are used to set various properties of the Texture.

Method Descriptions

  • void draw ( RID canvas_item, Vector2 position, Color modulate=Color( 1, 1, 1, 1 ), bool transpose=false, Texture normal_map=null ) const

Draws the texture using a CanvasItem with the VisualServer API at the specified position. Equivalent to VisualServer.canvas_item_add_texture_rect with a rect at position and the size of this Texture.


  • void draw_rect ( RID canvas_item, Rect2 rect, bool tile, Color modulate=Color( 1, 1, 1, 1 ), bool transpose=false, Texture normal_map=null ) const

Draws the texture using a CanvasItem with the VisualServer API. Equivalent to VisualServer.canvas_item_add_texture_rect.


  • void draw_rect_region ( RID canvas_item, Rect2 rect, Rect2 src_rect, Color modulate=Color( 1, 1, 1, 1 ), bool transpose=false, Texture normal_map=null, bool clip_uv=true ) const

Draws a part of the texture using a CanvasItem with the VisualServer API. Equivalent to VisualServer.canvas_item_add_texture_rect_region.


  • Image get_data ( ) const

Returns an Image with the data from this Texture. Images can be accessed and manipulated directly.


  • int get_height ( ) const

Returns the texture height.


Returns the texture size.


  • int get_width ( ) const

Returns the texture width.


  • bool has_alpha ( ) const

Returns true if this Texture has an alpha channel.