Naev

Module gfx

Lua bindings to interact with rendering and the Naev graphical environment.

An example would be:

 t  = tex.open( GFX_PATH"foo/bar.png" ) -- Loads the texture
 gfx.renderTex( t, 0., 0. ) -- Draws texture at origin
 

Functions

dim () Gets the dimensions of the Naev window.
renderTex (tex, pos_x, pos_y[, sprite_x=0[, sprite_y=0[, colour]]]) Renders a texture.
renderTexRaw (tex, pos_x, pos_y, pos_w, pos_h, sprite_x, sprite_y, tex_x, tex_y, tex_w, tex_h[, colour]) Renders a texture using the core render function.
renderRect (x, y, w, h, col[, empty=false]) Renders a rectangle.
fontSize (small) Gets the size of the font.
printDim (small, str[, width]) Gets the size of the text to print.
print (small, str, x, y, col[, max[, center]]) Prints text on the screen.
printText (small, str, x, y, w, h, col) Prints a block of text on the screen.


Functions

dim ()
Gets the dimensions of the Naev window. ()

Returns:

  1. number The width of the Naev window.
  2. number The height of the Naev window.

Usage:

    screen_w, screen_h = gfx.dim()
renderTex (tex, pos_x, pos_y[, sprite_x=0[, sprite_y=0[, colour]]])
Renders a texture.

This function has variable parameters depending on how you want to render. ( tex, pos_x, pos_y, sprite_x, sprite_y, colour )

Parameters:

  • tex Tex Texture to render.
  • pos_x number X position to render texture at.
  • pos_y number Y position to render texture at.
  • sprite_x int X sprite to render. (default 0)
  • sprite_y int Y sprite to render. (default 0)
  • colour Colour Colour to use when rendering. (optional)

Usage:

  • gfx.renderTex( tex, 0., 0. ) -- Render tex at origin
  • gfx.renderTex( tex, 0., 0., col ) -- Render tex at origin with colour col
  • gfx.renderTex( tex, 0., 0., 4, 3 ) -- Render sprite at position 4,3 (top-left is 1,1)
  • gfx.renderTex( tex, 0., 0., 4, 3, col ) -- Render sprite at position 4,3 (top-left is 1,1) with colour col
renderTexRaw (tex, pos_x, pos_y, pos_w, pos_h, sprite_x, sprite_y, tex_x, tex_y, tex_w, tex_h[, colour])
Renders a texture using the core render function.

This function is far more complex than renderTex, however it allows much more fine grained control over the entire render process and puts you closer to the actual OpenGL calls. ( tex, pos_x, pos_y, pos_w, pos_h, sprite_x, sprite_y, tex_x, tex_y, tex_w, tex_h, colour )

Parameters:

  • tex Tex Texture to render.
  • pos_x number X position to render texture at.
  • pos_y number Y position to render texture at.
  • pos_w number Width of the image on screen.
  • pos_h number Height of the image on screen.
  • sprite_x number X sprite to render.
  • sprite_y number Y sprite to render.
  • tex_x number X sprite texture offset as [0.:1.].
  • tex_y number Y sprite texture offset as [0.:1.].
  • tex_w number Sprite width to display as [-1.:1.]. Note if negative, it will flip the image horizontally.
  • tex_h number Sprite height to display as [-1.:1.] Note if negative, it will flip the image vertically.
  • colour Colour Colour to use when rendering. (optional)

Usage:

    gfx.renderTexRaw( tex, 0., 0., 100., 100., 1, 1, 0., 0., 0.5, 0.5 ) -- Renders the bottom quarter of the sprite 1,1 of the image.
renderRect (x, y, w, h, col[, empty=false])
Renders a rectangle. ( x, y, w, h, col, empty )

Parameters:

  • x number X position to render at.
  • y number Y position to render at.
  • w number Width of the rectangle.
  • h number Height of the rectangle.
  • col Colour Colour to use.
  • empty boolean Whether or not it should be empty. (default false)

Usage:

  • gfx.renderRect( 10., 30,. 40., 40., col ) -- Renders a 40 side square at position 10,30 of colour col
  • gfx.renderRect( 10., 30,. 40., 40., col, True ) -- Renders a 40 side empty square at position 10,30 of colour col
fontSize (small)
Gets the size of the font. ( small )

Parameters:

  • small boolean Whether or not to get the size of the small font.

Returns:

    The size in pixels of the font.
printDim (small, str[, width])
Gets the size of the text to print. ( small, str, width )

Parameters:

  • small boolean Whether or not to use the small font.
  • str string Text to calculate length of.
  • width int Optional parameter to indicate it is a block of text and to use this width. (optional)

Usage:

  • len = gfx.printDim( nil, "Hello World!" ) -- Length of string with normal font
  • height = gfx.printDim( true, "Longer text", 20 ) -- Dimensions of text block
print (small, str, x, y, col[, max[, center]])
Prints text on the screen. ( small, str, x, y, col, max, center )

Parameters:

  • small bookean Whether or not to use a small font.
  • str string String to print.
  • x number X position to print at.
  • y number Y position to print at.
  • col Colour Colour to print text.
  • max int Maximum width to render up to. (optional)
  • center boolean Whether or not to center it. (optional)

Usage:

  • gfx.print( nil, "Hello World!", 50, 50, colour.new("Red") ) -- Displays text in red at 50,50.
  • gfx.print( true, "Hello World!", 50, 50, col, 100 ) -- Displays text to a maximum of 100 pixels wide.
  • gfx.print( true, str, 50, 50, col, 100, true ) -- Displays centered text to a maximum of 100 pixels.
printText (small, str, x, y, w, h, col)
Prints a block of text on the screen. ( small, str, x, y, w, h, col )

Parameters:

  • small boolean Whether or not to use a small font.
  • str string String to print.
  • x number X position to print at.
  • y number Y position to print at.
  • w number Width of the block of text.
  • h number Height of the block of text.
  • col Colour Colour to print text.

Usage:

    gfx.printText( true, 100, 50, 50, 100, 100, col ) -- Displays a 100x100 block of text
generated by LDoc 1.4.6 Last updated 2020-10-01 02:30:07