Module tex
Lua bindings to interact with OpenGL textures.
This will allow you to load textures.
An example would be:
t = tex.open( "foo/bar.png" ) -- Loads the texture w,h, sw,sh = t:dim() sprites, sx,sy = t:sprites()
Functions
__gc (t) | Frees the texture. |
open (path[, w=1[, h=1[, sx=1[, sy=1]]]]) | Opens a texture. |
readData (File) | Reads image data from a file. |
toData (t) | Saves texture data as a png. |
dim (t) | Gets the dimensions of the texture. |
sprites (t) | Gets the number of sprites in the texture. |
spriteFromDir (t, a) | Gets the sprite that corresponds to a direction. |
setFilter (tex, min[, mag]) | Sets the texture minification and magnification filters. |
setWrap (tex, horiz[, vert[, depth]]) | Sets the texture wrapping. |
Functions
- __gc (t)
-
Frees the texture.
Parameters:
- t Tex Texture to free.
- open (path[, w=1[, h=1[, sx=1[, sy=1]]]])
-
Opens a texture.
Note open( path, (sx=1), (sy=1) ) Note open( file, (sx=1), (sy=1) ) Note open( data, w, h, (sx=1), (sy=1) )
Parameters:
- path string, File or Data Path, File, or Data to open.
- w number Width when Data or optional number of x sprites otherwise. (default 1)
- h number Height when Data or optional number of y sprites otherwise. (default 1)
- sx number Optional number of x sprites when path is Data. (default 1)
- sy number Optional number of y sprites when path is Data. (default 1)
Returns:
-
Tex
The opened texture or nil on error.
Usage:
t = tex.open( "no_sprites.png" )
t = tex.open( "spritesheet.png", 6, 6 )
- readData (File)
-
Reads image data from a file.
Parameters:
- File file |string File or filename of the file to read the data from.
Returns:
- Data Data containing the image data.
- number Width of the loaded data.
- number Height of the loaded data.
- toData (t)
-
Saves texture data as a png.
Parameters:
- t Tex Texture to convert to string.
Returns:
-
string
Texture as a string.
- dim (t)
-
Gets the dimensions of the texture.
Parameters:
- t Tex Texture to get dimensions of.
Returns:
- number The width the total image.
- number The height the total image.
- number The width the sprites.
- number The height the sprites.
Usage:
w,h, sw,sh = t:dim()
- sprites (t)
-
Gets the number of sprites in the texture.
Parameters:
- t Tex Texture to get sprites of.
Returns:
- number The total number of sprites.
- number The number of X sprites.
- number The number of Y sprites.
Usage:
sprites, sx,sy = t:sprites()
- spriteFromDir (t, a)
-
Gets the sprite that corresponds to a direction.
Parameters:
- t Tex Texture to get sprite of.
- a number Direction to have sprite facing (in radians).
Returns:
- number The x position of the sprite.
- number The y position of the sprite.
Usage:
sx, sy = t:spriteFromDir( math.pi )
- setFilter (tex, min[, mag])
-
Sets the texture minification and magnification filters.
Parameters:
- setWrap (tex, horiz[, vert[, depth]])
-
Sets the texture wrapping.
Parameters: