Texture

Refreshing Cache...

Inherits: Resource < Reference < Object

Inherited By: AnimatedTexture, AtlasTexture, CameraTexture, CurveTexture, 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

intflags4

Methods

voiddraw ( RID canvas_item, Vector2 position, Color modulate=Color( 1, 1, 1, 1 ), bool transpose=false, Texture normal_map=null ) const
voiddraw_rect ( RID canvas_item, Rect2 rect, bool tile, Color modulate=Color( 1, 1, 1, 1 ), bool transpose=false, Texture normal_map=null ) const
voiddraw_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
Imageget_data ( ) const
intget_height ( ) const
Vector2get_size ( ) const
intget_width ( ) const
boolhas_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

Default4
Setterset_flags(value)
Getterget_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.


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.

doradoro's advice! Getters and Setters will be deprecated! Avoid their use!

Disclaimer: This page has been automaticaly and directly extracted from the official Godot Docs website, the 2020-03-07 at 01:41:02. It's the English Stable version because it's what most Godot users should use. The Copyright owners are Juan Linietsky, Ariel Manzur and the Godot community. CC-BY 3.0. Thanks for your patience and generosity.