class_texture.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the Texture.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Texture:
  6. Texture
  7. =======
  8. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  9. **Inherited By:** :ref:`AnimatedTexture<class_AnimatedTexture>`, :ref:`AtlasTexture<class_AtlasTexture>`, :ref:`CameraTexture<class_CameraTexture>`, :ref:`CurveTexture<class_CurveTexture>`, :ref:`ExternalTexture<class_ExternalTexture>`, :ref:`GradientTexture<class_GradientTexture>`, :ref:`ImageTexture<class_ImageTexture>`, :ref:`LargeTexture<class_LargeTexture>`, :ref:`MeshTexture<class_MeshTexture>`, :ref:`NoiseTexture<class_NoiseTexture>`, :ref:`ProxyTexture<class_ProxyTexture>`, :ref:`StreamTexture<class_StreamTexture>`, :ref:`ViewportTexture<class_ViewportTexture>`
  10. Texture for 2D and 3D.
  11. Description
  12. -----------
  13. A texture works by registering an image in the video hardware, which then can be used in 3D models or 2D :ref:`Sprite<class_Sprite>` or GUI :ref:`Control<class_Control>`.
  14. Textures are often created by loading them from a file. See :ref:`@GDScript.load<class_@GDScript_method_load>`.
  15. ``Texture`` is a base for other resources. It cannot be used directly.
  16. Properties
  17. ----------
  18. +-----------------------+--------------------------------------------+-------+
  19. | :ref:`int<class_int>` | :ref:`flags<class_Texture_property_flags>` | ``4`` |
  20. +-----------------------+--------------------------------------------+-------+
  21. Methods
  22. -------
  23. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | void | :ref:`draw<class_Texture_method_draw>` **(** :ref:`RID<class_RID>` canvas_item, :ref:`Vector2<class_Vector2>` position, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`bool<class_bool>` transpose=false, :ref:`Texture<class_Texture>` normal_map=null **)** |const| |
  25. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | void | :ref:`draw_rect<class_Texture_method_draw_rect>` **(** :ref:`RID<class_RID>` canvas_item, :ref:`Rect2<class_Rect2>` rect, :ref:`bool<class_bool>` tile, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`bool<class_bool>` transpose=false, :ref:`Texture<class_Texture>` normal_map=null **)** |const| |
  27. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | void | :ref:`draw_rect_region<class_Texture_method_draw_rect_region>` **(** :ref:`RID<class_RID>` canvas_item, :ref:`Rect2<class_Rect2>` rect, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`bool<class_bool>` transpose=false, :ref:`Texture<class_Texture>` normal_map=null, :ref:`bool<class_bool>` clip_uv=true **)** |const| |
  29. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`Image<class_Image>` | :ref:`get_data<class_Texture_method_get_data>` **(** **)** |const| |
  31. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`int<class_int>` | :ref:`get_height<class_Texture_method_get_height>` **(** **)** |const| |
  33. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`Vector2<class_Vector2>` | :ref:`get_size<class_Texture_method_get_size>` **(** **)** |const| |
  35. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`int<class_int>` | :ref:`get_width<class_Texture_method_get_width>` **(** **)** |const| |
  37. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`bool<class_bool>` | :ref:`has_alpha<class_Texture_method_has_alpha>` **(** **)** |const| |
  39. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. Enumerations
  41. ------------
  42. .. _enum_Texture_Flags:
  43. .. _class_Texture_constant_FLAGS_DEFAULT:
  44. .. _class_Texture_constant_FLAG_MIPMAPS:
  45. .. _class_Texture_constant_FLAG_REPEAT:
  46. .. _class_Texture_constant_FLAG_FILTER:
  47. .. _class_Texture_constant_FLAG_ANISOTROPIC_FILTER:
  48. .. _class_Texture_constant_FLAG_CONVERT_TO_LINEAR:
  49. .. _class_Texture_constant_FLAG_MIRRORED_REPEAT:
  50. .. _class_Texture_constant_FLAG_VIDEO_SURFACE:
  51. enum **Flags**:
  52. - **FLAGS_DEFAULT** = **7** --- Default flags. :ref:`FLAG_MIPMAPS<class_Texture_constant_FLAG_MIPMAPS>`, :ref:`FLAG_REPEAT<class_Texture_constant_FLAG_REPEAT>` and :ref:`FLAG_FILTER<class_Texture_constant_FLAG_FILTER>` are enabled.
  53. - **FLAG_MIPMAPS** = **1** --- Generates mipmaps, which are smaller versions of the same texture to use when zoomed out, keeping the aspect ratio.
  54. - **FLAG_REPEAT** = **2** --- Repeats the texture (instead of clamp to edge).
  55. - **FLAG_FILTER** = **4** --- Uses a magnifying filter, to enable smooth zooming in of the texture.
  56. - **FLAG_ANISOTROPIC_FILTER** = **8** --- Uses anisotropic mipmap filtering. Generates smaller versions of the same texture with different aspect ratios.
  57. This results in better-looking textures when viewed from oblique angles.
  58. - **FLAG_CONVERT_TO_LINEAR** = **16** --- Converts the texture to the sRGB color space.
  59. - **FLAG_MIRRORED_REPEAT** = **32** --- Repeats the texture with alternate sections mirrored.
  60. - **FLAG_VIDEO_SURFACE** = **2048** --- Texture is a video surface.
  61. Property Descriptions
  62. ---------------------
  63. .. _class_Texture_property_flags:
  64. - :ref:`int<class_int>` **flags**
  65. +-----------+------------------+
  66. | *Default* | ``4`` |
  67. +-----------+------------------+
  68. | *Setter* | set_flags(value) |
  69. +-----------+------------------+
  70. | *Getter* | get_flags() |
  71. +-----------+------------------+
  72. The texture's :ref:`Flags<enum_Texture_Flags>`. :ref:`Flags<enum_Texture_Flags>` are used to set various properties of the ``Texture``.
  73. Method Descriptions
  74. -------------------
  75. .. _class_Texture_method_draw:
  76. - void **draw** **(** :ref:`RID<class_RID>` canvas_item, :ref:`Vector2<class_Vector2>` position, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`bool<class_bool>` transpose=false, :ref:`Texture<class_Texture>` normal_map=null **)** |const|
  77. Draws the texture using a :ref:`CanvasItem<class_CanvasItem>` with the :ref:`VisualServer<class_VisualServer>` API at the specified ``position``. Equivalent to :ref:`VisualServer.canvas_item_add_texture_rect<class_VisualServer_method_canvas_item_add_texture_rect>` with a rect at ``position`` and the size of this ``Texture``.
  78. ----
  79. .. _class_Texture_method_draw_rect:
  80. - void **draw_rect** **(** :ref:`RID<class_RID>` canvas_item, :ref:`Rect2<class_Rect2>` rect, :ref:`bool<class_bool>` tile, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`bool<class_bool>` transpose=false, :ref:`Texture<class_Texture>` normal_map=null **)** |const|
  81. Draws the texture using a :ref:`CanvasItem<class_CanvasItem>` with the :ref:`VisualServer<class_VisualServer>` API. Equivalent to :ref:`VisualServer.canvas_item_add_texture_rect<class_VisualServer_method_canvas_item_add_texture_rect>`.
  82. ----
  83. .. _class_Texture_method_draw_rect_region:
  84. - void **draw_rect_region** **(** :ref:`RID<class_RID>` canvas_item, :ref:`Rect2<class_Rect2>` rect, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Color<class_Color>` modulate=Color( 1, 1, 1, 1 ), :ref:`bool<class_bool>` transpose=false, :ref:`Texture<class_Texture>` normal_map=null, :ref:`bool<class_bool>` clip_uv=true **)** |const|
  85. Draws a part of the texture using a :ref:`CanvasItem<class_CanvasItem>` with the :ref:`VisualServer<class_VisualServer>` API. Equivalent to :ref:`VisualServer.canvas_item_add_texture_rect_region<class_VisualServer_method_canvas_item_add_texture_rect_region>`.
  86. ----
  87. .. _class_Texture_method_get_data:
  88. - :ref:`Image<class_Image>` **get_data** **(** **)** |const|
  89. Returns an :ref:`Image<class_Image>` that is a copy of data from this ``Texture``. :ref:`Image<class_Image>`\ s can be accessed and manipulated directly.
  90. ----
  91. .. _class_Texture_method_get_height:
  92. - :ref:`int<class_int>` **get_height** **(** **)** |const|
  93. Returns the texture height.
  94. ----
  95. .. _class_Texture_method_get_size:
  96. - :ref:`Vector2<class_Vector2>` **get_size** **(** **)** |const|
  97. Returns the texture size.
  98. ----
  99. .. _class_Texture_method_get_width:
  100. - :ref:`int<class_int>` **get_width** **(** **)** |const|
  101. Returns the texture width.
  102. ----
  103. .. _class_Texture_method_has_alpha:
  104. - :ref:`bool<class_bool>` **has_alpha** **(** **)** |const|
  105. Returns ``true`` if this ``Texture`` has an alpha channel.
  106. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  107. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  108. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`