Module ctr.gfx.texture

The gfx.texture module.

Usage:

    local texture = require("ctr.gfx.texture")

Functions

load (path[, place=PLACE_RAM[, type=auto]]) Load a texture from a file.
new (width, height[, place=PLACE_RAM]) Create an empty texture.

Texture object

:draw (x, y[, rad=0.0[, hotspotX=0.0[, hotspotY=0.0]]]) Draw a texture.
:drawPart (x, y, sx, sy, w, h[, rad=0.0[, hotspotX=0.0[, hotspotY=0.0]]]) Draw a part of the texture
:getSize () Return the size of the texture.
:unload () Unload a texture.
:scale (scaleX[, scaleY=scaleX]) Rescale the texture.
:getPixel (x, y) Return the color of a pixel.
:setPixel (x, y, color) Set the color of a pixel.
:setBlendColor (color) Set the blend color of the texture.
:getBlendColor () Get the blend color of the texture.
:save (filename[, type=TYPE_PNG]) Save a texture to a file.

Fields

PLACE_RAM Constant used to select the RAM.
PLACE_VRAM Constant used to select the VRAM.
TYPE_PNG Constant used to select the PNG type.
TYPE_JPEG Constant used to select the JPEG type.
TYPE_BMP Constant used to select the BMP type.


Functions

load (path[, place=PLACE_RAM[, type=auto]])
Load a texture from a file. Supported formats: PNG, JPEG, BMP, GIF, PSD, TGA, HDR, PIC, PNM.

Parameters:

  • path string path to the image file
  • place number where to put the loaded texture (default PLACE_RAM)
  • type number type of the image. This is only used to force loading PNG, JPEG or BMP files with the sfil library; any value between 5 and 250 will force using the stbi library. Leave nil to autodetect the format. (default auto)

Returns:

    texture the loaded texture object

Or

  1. nil in case of error
  2. string error message
new (width, height[, place=PLACE_RAM])
Create an empty texture.

Parameters:

  • width number Texture width
  • height number Texture height
  • place number where to put the loaded texture (default PLACE_RAM)

Returns:

    texture the loaded texture object

Texture object

:draw (x, y[, rad=0.0[, hotspotX=0.0[, hotspotY=0.0]]])
Draw a texture.

Parameters:

  • x integer X position
  • y integer Y position
  • rad number rotation of the texture around the hotspot (in radians) (default 0.0)
  • hotspotX number the hostpot X coordinate (default 0.0)
  • hotspotY number the hostpot Y coordinate (default 0.0)
:drawPart (x, y, sx, sy, w, h[, rad=0.0[, hotspotX=0.0[, hotspotY=0.0]]])
Draw a part of the texture

Parameters:

  • x integer X position
  • y integer Y position
  • sx integer X position of the beginning of the part
  • sy integer Y position of the beginning of the part
  • w integer width of the part
  • h integer height of the part
  • rad number rotation of the part around the hotspot (in radians) (default 0.0)
  • hotspotX number the hostpot X coordinate (default 0.0)
  • hotspotY number the hostpot Y coordinate (default 0.0)
:getSize ()
Return the size of the texture.

Returns:

  1. number width of the texture
  2. number height of the texture
:unload ()
Unload a texture.
:scale (scaleX[, scaleY=scaleX])
Rescale the texture. The default scale is 1.0.

Parameters:

  • scaleX number new scale of the width
  • scaleY number new scale of the height (default scaleX)
:getPixel (x, y)
Return the color of a pixel.

Parameters:

  • x number X position of the pixel
  • y number Y position of the pixel

Returns:

    number color of the pixel.
:setPixel (x, y, color)
Set the color of a pixel.

Parameters:

  • x number X position of the pixel
  • y number Y position of the pixel
  • color number New color of the pixel
:setBlendColor (color)
Set the blend color of the texture.

Parameters:

  • color number new blend color
:getBlendColor ()
Get the blend color of the texture.

Returns:

    number the blend color
:save (filename[, type=TYPE_PNG])
Save a texture to a file.

Parameters:

  • filename string path to the file to save the texture to
  • type number type of the image to save. Can be TYPE_PNG or TYPE_BMP (default TYPE_PNG)

Returns:

    boolean true on success

Or

  1. boolean false in case of error
  2. string error message

Fields

PLACE_RAM
Constant used to select the RAM.
  • PLACE_RAM
PLACE_VRAM
Constant used to select the VRAM.
  • PLACE_VRAM
TYPE_PNG
Constant used to select the PNG type.
  • TYPE_PNG
TYPE_JPEG
Constant used to select the JPEG type.
  • TYPE_JPEG
TYPE_BMP
Constant used to select the BMP type.
  • TYPE_BMP
generated by LDoc 1.4.3 Last updated 2017-06-05 14:35:27