Difference between revisions of "Texture.new"

From GiderosMobile
Line 15: Line 15:
  
 
* '''transparentColor''': specify which color stands for transparent for formats that don't supply an alpha channel such as JPEG
 
* '''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 default '''Texture.CLAMP''' and Texture.REPEAT
+
* '''wrap''': how to treat texels outside the texture. Possible values are Texture.CLAMP ('''default''') and Texture.REPEAT
* '''format''': the GPU pixel format for the texture, default '''RGBA8888'''
+
* '''format''': the GPU pixel format for the texture ('''default = RGBA8888''')
* '''extend''': whether the texture should be extended to a power of two size, default '''true'''
+
* '''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'''
+
* '''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'''
+
* '''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'''
+
* '''mipmap''': enable mipmaping ('''new 2022.6''') ('''default = false''')
  
=== Example ===
+
=== Examples ===
 
<source lang="lua">
 
<source lang="lua">
 
-- do not filter and make the color 0xff00ff transparent
 
-- do not filter and make the color 0xff00ff transparent
local texture = Texture.new("image.png", false, {transparentColor = 0xff00ff})
+
local texture = Texture.new("image.jpg", false, {transparentColor = 0xff00ff})
 
-- enable filtering and repeat the texture
 
-- enable filtering and repeat the texture
 
local texture = Texture.new("image.png", true, {wrap = Texture.REPEAT})
 
local texture = Texture.new("image.png", true, {wrap = Texture.REPEAT})
Line 51: Line 51:
  
 
* '''transparentColor''': specify which color stands for transparent for formats that don't supply an alpha channel such as JPEG
 
* '''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 default '''Texture.CLAMP''' and Texture.REPEAT
+
* '''wrap''': how to treat texels outside the texture. Possible values are Texture.CLAMP ('''default''') and Texture.REPEAT
* '''format''': the GPU pixel format for the texture, default '''RGBA8888'''
+
* '''format''': the GPU pixel format for the texture ('''default = RGBA8888''')
* '''extend''': whether the texture should be extended to a power of two size, default '''true'''
+
* '''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'''
+
* '''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'''
+
* '''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'''
+
* '''mipmap''': enable mipmaping ('''new 2022.6''') ('''default = false''')
  
 
=== Example ===
 
=== Example ===
 
<source lang="lua">
 
<source lang="lua">
 
-- Create a 300x400 empty texture. Prevent gideros from extending the texture to the next power of two size
 
-- 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})
+
local texture = Texture.new(nil, 300, 400, false, {extend=false})
 
</source>
 
</source>
  
 
{{Texture}}
 
{{Texture}}

Revision as of 03:30, 28 January 2023

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
options: (table, optional) a table that specifies optional parameters. 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 Texture.CLAMP (default) and Texture.REPEAT
  • format: the GPU pixel format for the texture (default = RGBA8888)
  • 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)

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 to false) indicates that the texture should be filtered optional
options: (table, optional) a table that specifies optional parameters. 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 Texture.CLAMP (default) and Texture.REPEAT
  • format: the GPU pixel format for the texture (default = RGBA8888)
  • 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})