Difference between revisions of "Texture.new"

From GiderosMobile
(Texture to TextureBase)
 
(17 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
'''Available since:''' Gideros 2011.6<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/Texture|Texture]]<br/>
+
'''Class:''' [[Texture]]<br/>
=== <translate>Description</translate> ===
+
 
<translate><br />
+
=== Description ===
Creates a new Texture object.<br />
+
Creates a new Texture object.
<br /></translate>
+
<syntaxhighlight lang="lua">
<source lang="lua">
+
Texture.new(filename,filtering,options)
Texture.new(filename,filtering,options)
+
</syntaxhighlight>
</source>
+
 
=== <translate>Parameters</translate> ===
+
=== Parameters ===
'''filename''': (string) <translate>The name of the texture file to be loaded.</translate> <br/>
+
'''filename''': (string) the name of the texture file to be loaded<br/>
'''filtering''': (boolean, default = false) <translate>Whether or not the texture is filtered.</translate> <br/>
+
'''filtering''': (boolean, default = false) whether or not the texture is filtered, that is smoothing the image (''blurry'') '''optional'''<br/>
'''options''': (table, optional) <translate>A table that specifies optional paramaters. Currently, "transparentColor", "wrap", "format" and "extend" fields are supported.</translate> '''optional'''<br/>
+
'''options''': (table) a table that specifies optional parameters '''optional'''. The following options are supported:<br/>
=== <translate>Examples</translate> ===
+
 
'''Example'''<br/>
+
* '''transparentColor''': specify which color stands for transparent for formats that don't supply an alpha channel such as JPEG
<source lang="lua">local texture = Texture.new(&quot;image.png&quot;, false, {transparentColor = 0xff00ff}) -- do not filter and make the color 0xff00ff transparent
+
* '''wrap''': how to treat texels outside the texture. Possible values are TextureBase.CLAMP ('''default''') and TextureBase.REPEAT
local texture = Texture.new(&quot;image.png&quot;, true, {wrap = Texture.REPEAT}) -- enable filtering and repeat the texture</source>
+
* '''format''': the GPU pixel format for the texture ('''default = RGBA8888''') see '''[[TextureBase]]'''
 +
* '''extend''': whether the texture should be extended to a power of two size ('''default = true''')
 +
* '''scale''': the scale at which this texture was made, if it cannot be determined by a suffix ('''default = 1''')
 +
* '''rawalpha''': disable alpha premultiplication. This can be helpful if one wants to store specific data in the alpha channel of a texture along with a dedicated shader ('''new 2022.3''') ('''default = false''')
 +
* '''mipmap''': enable mipmaping ('''new 2022.6''') ('''default = false'''), for more info see https://www.khronos.org/opengl/wiki/Texture#Mip_maps
 +
 
 +
=== Examples ===
 +
<syntaxhighlight lang="lua">
 +
-- do not filter and make the color 0xff00ff transparent
 +
local texture = Texture.new("image.jpg", false, {transparentColor = 0xff00ff})
 +
-- enable filtering and repeat the texture
 +
local texture = Texture.new("image.png", true, {wrap = Texture.REPEAT})
 +
</syntaxhighlight>
 +
 
 +
 
 +
----
 +
 
 
__NOTOC__
 
__NOTOC__
'''<translate>Available since</translate>:''' Gideros 2016.08<br/>
+
'''Available since:''' Gideros 2016.08<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/Texture|Texture]]<br/>
+
'''Class:''' [[Texture]]<br/>
=== <translate>Description</translate> ===
+
 
<translate>Create a texture from pixel data.</translate>
+
=== Description ===
<source lang="lua">
+
Creates a texture from pixel data.
Texture.new(pixels,width,height,filtering,options)
+
<syntaxhighlight lang="lua">
</source>
+
Texture.new(pixels,width,height,filtering,options)
=== <translate>Parameters</translate> ===
+
</syntaxhighlight>
'''pixels''': (string) <translate>A string containing actual R,G,B,A compoents of each pixel in the new texture. Each component is stored as a byte. You can pass nil if you don't need to initialize texture content</translate> <br/>
+
 
'''width''': (number) <translate>width of the texture to create</translate> <br/>
+
=== Parameters ===
'''height''': (number) <translate>Height of the texture to create</translate> <br/>
+
'''pixels''': (string) a string containing actual R,G,B,A components of each pixel in the new texture. Each component is stored as a byte. You can pass nil if you don't need to initialize texture content<br/>
'''filtering''': (boolean, default to false) <translate>indicate that the texture should be filtered</translate> '''optional'''<br/>
+
'''width''': (number) width of the texture to create<br/>
'''options''': (table, optional) <translate>A table that specifies optional paramaters. Currently, "transparentColor", "wrap", "format" and "extend" fields are supported.</translate> '''optional'''<br/>
+
'''height''': (number) height of the texture to create<br/>
=== <translate>Examples</translate> ===
+
'''filtering''': (boolean, default = false) indicates that the texture should be filtered, that is smoothing the image (''blurry'') '''optional'''<br/>
'''Example'''<br/>
+
'''options''': (table) a table that specifies optional parameters '''optional'''. The following options are supported:<br/>
<source lang="lua">local texture = Texture.new(nil,300,400;, false, {extend=false}) -- Create a 300x400 empty texture. Prevent gideros from extending the texture to the next power of two size</source>
+
 
 +
* '''transparentColor''': specify which color stands for transparent for formats that don't supply an alpha channel such as JPEG
 +
* '''wrap''': how to treat texels outside the texture. Possible values are TextureBase.CLAMP ('''default''') and TextureBase.REPEAT
 +
* '''format''': the GPU pixel format for the texture ('''default = RGBA8888''') see '''[[TextureBase]]'''
 +
* '''extend''': whether the texture should be extended to a power of two size ('''default = true''')
 +
* '''scale''': the scale at which this texture was made, if it cannot be determined by a suffix ('''default = 1''')
 +
* '''rawalpha''': disable alpha premultiplication. This can be helpful if one wants to store specific data in the alpha channel of a texture along with a dedicated shader ('''new 2022.3''') ('''default = false''')
 +
* '''mipmap''': enable mipmaping ('''new 2022.6''') ('''default = false''')
 +
 
 +
=== Example ===
 +
<syntaxhighlight lang="lua">
 +
-- Create a 300x400 empty texture. Prevent gideros from extending the texture to the next power of two size
 +
local texture = Texture.new(nil, 300, 400, false, {extend=false})
 +
</syntaxhighlight>
 +
 
 +
{{Texture}}

Latest revision as of 14:30, 20 July 2024

Available since: Gideros 2011.6
Class: Texture

Description

Creates a new Texture object.

Texture.new(filename,filtering,options)

Parameters

filename: (string) the name of the texture file to be loaded
filtering: (boolean, default = false) whether or not the texture is filtered, that is smoothing the image (blurry) optional
options: (table) a table that specifies optional parameters optional. The following options are supported:

  • transparentColor: specify which color stands for transparent for formats that don't supply an alpha channel such as JPEG
  • wrap: how to treat texels outside the texture. Possible values are TextureBase.CLAMP (default) and TextureBase.REPEAT
  • format: the GPU pixel format for the texture (default = RGBA8888) see TextureBase
  • extend: whether the texture should be extended to a power of two size (default = true)
  • scale: the scale at which this texture was made, if it cannot be determined by a suffix (default = 1)
  • rawalpha: disable alpha premultiplication. This can be helpful if one wants to store specific data in the alpha channel of a texture along with a dedicated shader (new 2022.3) (default = false)
  • mipmap: enable mipmaping (new 2022.6) (default = false), for more info see https://www.khronos.org/opengl/wiki/Texture#Mip_maps

Examples

-- do not filter and make the color 0xff00ff transparent
local texture = Texture.new("image.jpg", false, {transparentColor = 0xff00ff})
-- enable filtering and repeat the texture
local texture = Texture.new("image.png", true, {wrap = Texture.REPEAT})




Available since: Gideros 2016.08
Class: Texture

Description

Creates a texture from pixel data.

Texture.new(pixels,width,height,filtering,options)

Parameters

pixels: (string) a string containing actual R,G,B,A components of each pixel in the new texture. Each component is stored as a byte. You can pass nil if you don't need to initialize texture content
width: (number) width of the texture to create
height: (number) height of the texture to create
filtering: (boolean, default = false) indicates that the texture should be filtered, that is smoothing the image (blurry) optional
options: (table) a table that specifies optional parameters optional. The following options are supported:

  • transparentColor: specify which color stands for transparent for formats that don't supply an alpha channel such as JPEG
  • wrap: how to treat texels outside the texture. Possible values are TextureBase.CLAMP (default) and TextureBase.REPEAT
  • format: the GPU pixel format for the texture (default = RGBA8888) see TextureBase
  • extend: whether the texture should be extended to a power of two size (default = true)
  • scale: the scale at which this texture was made, if it cannot be determined by a suffix (default = 1)
  • rawalpha: disable alpha premultiplication. This can be helpful if one wants to store specific data in the alpha channel of a texture along with a dedicated shader (new 2022.3) (default = false)
  • mipmap: enable mipmaping (new 2022.6) (default = false)

Example

-- Create a 300x400 empty texture. Prevent gideros from extending the texture to the next power of two size
local texture = Texture.new(nil, 300, 400, false, {extend=false})