Home

Module tex

Lua bindings to interact with OpenGL textures. This will allow you to load textures. An example would be:
 t  = tex.open( GFX_PATH"foo/bar.png" ) -- Loads the texture
 w,h, sw,sh = t:dim()
 sprites, sx,sy = t:sprites()
 

Functions

tex.__gc (t) Frees the texture.
tex.dim (t) Gets the dimensions of the texture.
tex.open (path, sx, sy) Opens a texture.
tex.spriteFromDir (t, a, b) Gets the sprite that corresponds to a direction.
tex.sprites (t) Gets the number of sprites in the texture.


Functions

tex.__gc (t)
Frees the texture.

Parameters

  • t: Texture to free.
tex.dim (t)
Gets the dimensions of the texture.

Parameters

  • t: Texture to get dimensions of.

Usage:

w,h, sw,sh = t:dim()

Return value:

The width and height of the total image followed by the width and height of the sprites.
tex.open (path, sx, sy)
Opens a texture.

Parameters

  • path: Path to open.
  • sx: Optional number of x sprites (defaults 1).
  • sy: Optional number of y sprites (defaults 1).

Usage

  • t = tex.open( "no_sprites.png" )
  • t = tex.open( "spritesheet.png", 6, 6 )

Return value:

The opened texture or nil on error.
tex.spriteFromDir (t, a, b)
Gets the sprite that corresponds to a direction.

Parameters

  • t: Texture to get sprite of.
  • a: Direction to have sprite facing (in degrees).
  • b: Whether radians should be used instead of degrees.

Usage:

sx, sy = t:spriteFromdir( math.pi )

Return value:

x and y positions of the sprite.
tex.sprites (t)
Gets the number of sprites in the texture.

Parameters

  • t: Texture to get sprites of.

Usage:

sprites, sx,sy = t:sprites()

Return value:

The total number of sprites followed by the number of X sprites and the number of Y sprites.

Valid XHTML 1.0!