Naev

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.
dim (t) Gets the dimensions of the texture.
sprites (t) Gets the number of sprites in the texture.
spriteFromDir (t, a[, b=false]) 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:

  1. Data Data containing the image data.
  2. number Width of the loaded data.
  3. number Height of the loaded data.
dim (t)
Gets the dimensions of the texture.

Parameters:

  • t Tex Texture to get dimensions of.

Returns:

  1. number The width the total image.
  2. number The height the total image.
  3. number The width the sprites.
  4. 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:

  1. number The total number of sprites.
  2. number The number of X sprites.
  3. number The number of Y sprites.

Usage:

    sprites, sx,sy = t:sprites()
spriteFromDir (t, a[, b=false])
Gets the sprite that corresponds to a direction.

Parameters:

  • t Tex Texture to get sprite of.
  • a number Direction to have sprite facing (in degrees).
  • b boolean Whether radians should be used instead of degrees. (default false)

Returns:

  1. number The x position of the sprite.
  2. 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:

  • tex Tex Texture to set filter.
  • min string Minification filter ("nearest" or "linear")
  • mag string Magnification filter ("nearest" or "linear"). Defaults to min. (optional)
setWrap (tex, horiz[, vert[, depth]])
Sets the texture wrapping.

Parameters:

  • tex Tex Texture to set filter.
  • horiz string Horizontal wrapping ("clamp", "repeat", or "mirroredrepeat" )
  • vert string Vertical wrapping ("clamp", "repeat", or "mirroredrepeat" ) (optional)
  • depth string Depth wrapping ("clamp", "repeat", or "mirroredrepeat" ) (optional)
generated by LDoc 1.4.6 Last updated 2021-02-27 10:35:56