Home

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

gfx.dim () Gets the dimensions of the Naev window.
gfx.fontSize (small) Gets the size of the font.
gfx.print (small, str, x, y, col, max, center) Prints text on the screen.
gfx.printDim (small, str, width) Gets the size of the text to print.
gfx.printText (small, str, x, y, w, h, col) Prints a block of text on the screen.
gfx.renderRect (x, y, w, h, col, empty) Renders a rectangle.
gfx.renderTex (tex, pos_x, pos_y, sprite_x, sprite_y, colour) Renders a texture.
gfx.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.


Functions

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

Usage:

screen_w, screen_h = gfx.dim()

Return value:

The width and height of the Naev window.
gfx.fontSize (small)
Gets the size of the font.

Parameters

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

Return value:

The size in pixels of the font.
gfx.print (small, str, x, y, col, max, center)
Prints text on the screen.

Parameters

  • small: Whether or not to use a small font.
  • str: String to print.
  • x: X position to print at.
  • y: Y position to print at.
  • col: Colour to print text.
  • max: Optional parameter to indicate maximum width to render up to.
  • center: Optional boolean parameter indicating whether or not to center it.

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.
gfx.printDim (small, str, width)
Gets the size of the text to print.

Parameters

  • small: Whether or not to use the small font.
  • str: Text to calculate length of.
  • width: Optional parameter to indicate it is a block of text and to use this width.

Usage

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

Parameters

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

Usage:

gfx.printText( true, 100, 50, 50, 100, 100, col ) -- Displays a 100x100 block of text
gfx.renderRect (x, y, w, h, col, empty)
Renders a rectangle.

Parameters

  • x: X position to render at.
  • y: Y position to render at.
  • w: Width of the rectangle.
  • h: Height of the rectangle.
  • col: Colour to use.
  • empty: Optional parameter on whether or not it should be empty, defaults to true.

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
gfx.renderTex (tex, pos_x, pos_y, sprite_x, sprite_y, colour)
Renders a texture. This function has variable parameters depending on how you want to render.

Parameters

  • tex: Texture to render.
  • pos_x: X position to render texture at.
  • pos_y: Y position to render texture at.
  • sprite_x: X sprite to render.
  • sprite_y: Y sprite to render.
  • colour: Colour to use when rendering.

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
gfx.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.

Parameters

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

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.

Valid XHTML 1.0!