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 ([internalsize=false]) Gets the dimensions of the Naev window.
screencoords (Vector[, Whether=false]) Gets the screen coordinates from game coordinates.
renderTex (tex, pos_x, pos_y[, sprite_x=0[, sprite_y=0[, colour]]]) Renders a texture.
renderTexScale (tex, pos_x, pos_y, bw, bh[, sprite_x=0[, sprite_y=0[, colour]]]) DEPRECATED: Renders a texture, scaled.
renderTexRaw (tex, pos_x, pos_y, pos_w, pos_h[, sprite_x=1[, sprite_y=1[, tex_x=0.[, tex_y=0.[, tex_w=1.[, tex_h=1.[, colour[, angle]]]]]]]]) Renders a texture using the core render function.
renderTexH (tex, shader, H[, colour=white]) Renders a texture using a transformation matrix.
renderRect (x, y, w, h, col[, empty=false]) Renders a rectangle.
renderRectH (H[, col=white[, empty=false]]) Renders a rectangle given a transformation matrix.
renderCircle (x, y, r, col[, empty=false]) Renders a circle
renderCircleH (H[, col=white[, empty=false]]) Renders a circle given a transformation matrix.
renderLinesH (H, Colour, Either) Renders a polyline or set of line segments.
fontSize (small) Gets the size of the font.
printDim (small, str[, width]) Gets the size of the text to print.
printfDim (font, str[, width]) Gets the size of the text to print.
printfWrap (font, str, width) Gets the wrap for text.
printRestoreClear () Clears the saved internal colour state.
printRestoreLast () Restores the last saved internal colour state.
printf (font, str, x, y, col[, max[, center]]) Prints text on the screen using a font.
printH (H, font, str[, col=white[, outline=0]]) Prints text on the screen using a font with a transformation matirx.
print (small, str, x, y, col[, max[, center]]) Prints text on the screen.
printText (small, str, x, y, w, h, col, Height) Prints a block of text on the screen.
setBlendMode (mode[, alphamode="alphamultiply"]) Sets the OpenGL blending mode.
setScissor (x, y, width, height) Sets the scissor clipping.
screenshot ([c=nil]) Takes the current rendered game screen and returns it as a canvas.
lightAmbient (r[, g=r[, b=r[, strength]]]) Sets the ambient lighting.
lightAmbientGet () Gets the ambient lighting values.
lightIntensity (intensity) Sets the intensity of the main lights excluding ambient lighting.
lightIntensityGet () Gets the light intensity.
glVersion () Gets the OpenGL version.


Functions

dim ([internalsize=false])
Gets the dimensions of the Naev window.

Parameters:

  • internalsize boolean Whether or not to consider the GUI modifications to the screen size. (default false)

Returns:

  1. number The width of the Naev window.
  2. number The height of the Naev window.
  3. scale The scaling factor.

Usage:

    screen_w, screen_h = gfx.dim()
    
screencoords (Vector[, Whether=false])
Gets the screen coordinates from game coordinates.

Parameters:

  • Vector Vec2 of coordinates to transnform.
  • Whether boolean or not to invert y axis. (default false)

Returns:

    Vec2 Transformed vector.
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.

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
    
renderTexScale (tex, pos_x, pos_y, bw, bh[, sprite_x=0[, sprite_y=0[, colour]]])
DEPRECATED: Renders a texture, scaled. Ultimately, love.graphics should handle this.

Parameters:

  • tex Tex Texture to render.
  • pos_x number X position to render texture at.
  • pos_y number Y position to render texture at.
  • bw number Width to scale to.
  • bh number Height to scale to.
  • 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)
renderTexRaw (tex, pos_x, pos_y, pos_w, pos_h[, sprite_x=1[, sprite_y=1[, tex_x=0.[, tex_y=0.[, tex_w=1.[, tex_h=1.[, colour[, angle]]]]]]]])
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 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. (default 1)
  • sprite_y number Y sprite to render. (default 1)
  • tex_x number X sprite texture offset as [0.:1.]. (default 0.)
  • tex_y number Y sprite texture offset as [0.:1.]. (default 0.)
  • tex_w number Sprite width to display as [-1.:1.]. Note if negative, it will flip the image horizontally. (default 1.)
  • tex_h number Sprite height to display as [-1.:1.] Note if negative, it will flip the image vertically. (default 1.)
  • colour Colour Colour to use when rendering. (optional)
  • angle number Angle to rotate in radians. (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.
    
renderTexH (tex, shader, H[, colour=white])
Renders a texture using a transformation matrix.

Parameters:

  • tex Tex Texture to render.
  • shader Shader Shader to use when rendering.
  • H Transformation Transformation matrix to use.
  • colour Colour Colour to use or white if not set. (default white)
renderRect (x, y, w, h, col[, empty=false])
Renders a rectangle.

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
    
renderRectH (H[, col=white[, empty=false]])
Renders a rectangle given a transformation matrix.

Parameters:

  • H Transform Transformation matrix to use.
  • col Colour Colour to use. (default white)
  • empty boolean Whether or not it should be empty. (default false)
renderCircle (x, y, r, col[, empty=false])
Renders a circle

Parameters:

  • x number X position to render at.
  • y number Y position to render at.
  • r number Radius of the circle.
  • col Colour Colour to use.
  • empty boolean Whether or not it should be empty. (default false)
renderCircleH (H[, col=white[, empty=false]])
Renders a circle given a transformation matrix.

Parameters:

  • H Transform Transformation matrix to use.
  • col Colour Colour to use. (default white)
  • empty boolean Whether or not it should be empty. (default false)
renderLinesH (H, Colour, Either)
Renders a polyline or set of line segments.

Parameters:

  • H Transform Transform to use when rendering.
  • Colour Colour to use when drawing.
  • Either number or Vec2 a set of x/y coordinates or 2D vector.

Usage:

  • gfx.renderLinesH( 50,30, 70,70 )
    
  • gfx.renderLinesH( vec2.new(), vec2.new(100,100), vec2.new(200,100) )
    
fontSize (small)
Gets the size of the font.

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.

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
    
printfDim (font, str[, width])
Gets the size of the text to print.

Parameters:

  • font font Font to use.
  • 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)
printfWrap (font, str, width)
Gets the wrap for text.

Parameters:

  • font font Font to use.
  • str string Text to calculate length of.
  • width int Width to wrap at.

Returns:

  1. table A table containing pairs of text and their width.
  2. number Maximum width of all the lines.
printRestoreClear ()
Clears the saved internal colour state.
printRestoreLast ()
Restores the last saved internal colour state.
printf (font, str, x, y, col[, max[, center]])
Prints text on the screen using a font.

Parameters:

  • font font Font to use.
  • 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.printf( font, _("Hello World!"), 50, 50, colour.new("Red") ) --
    Displays text in red at 50,50.
    
printH (H, font, str[, col=white[, outline=0]])
Prints text on the screen using a font with a transformation matirx.

Parameters:

  • H Transform transformation matrix to use.
  • font font Font to use.
  • str string String to print.
  • col Colour Colour to print text. (default white)
  • outline number How big to make an outline. (default 0)
print (small, str, x, y, col[, max[, center]])
Prints text on the screen.

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.
  • 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, Height)
Prints a block of text on the screen.

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.
  • Height line_height of each line to print.

Usage:

    gfx.printText( true, 100, 50, 50, 100, 100, col ) -- Displays a
    100x100 block of text
    
setBlendMode (mode[, alphamode="alphamultiply"])
Sets the OpenGL blending mode. See https://love2d.org/wiki/love.graphics.setBlendMode as of version 0.10.

Parameters:

  • mode string One of: "alpha", "replace", "screen", "add", "subtract", "multiply", "lighten", or "darken".
  • alphamode string Override to "premultiplied" when drawing canvases; see https://love2d.org/wiki/BlendAlphaMode. (default "alphamultiply")

Usage:

    gfx.setBlendMode( "alpha", "premultiplied" )
    
setScissor (x, y, width, height)
Sets the scissor clipping.

Calling setScissor with no parameters disables the clipping.

Parameters:

  • x number X position of the clipping rectangle.
  • y number Y position of the clipping rectangle.
  • width number Width of the clipping rectangle.
  • height number Height of the clipping rectangle.
screenshot ([c=nil])
Takes the current rendered game screen and returns it as a canvas.

Parameters:

  • c Canvas Canvas to use instead of creating a new one. (default nil)

Returns:

    Canvas A new canvas or parameter canvas if available with the screen data in it.
lightAmbient (r[, g=r[, b=r[, strength]]])
Sets the ambient lighting.

Parameters:

  • r Colour or number Colour or red channel to use for ambient lighting. In the case of a colour, the alpha channel is used as the radiance value of the ambient light.
  • g number Green channel to use for ambient lighting. (default r)
  • b number Blue channel to use for ambient lighting. (default r)
  • strength number If defined, normalizes the values of r, g, and b so that the total radiance is equal to strength. If not, the values of r, g, and b are considered to be radiance values. (optional)
lightAmbientGet ()
Gets the ambient lighting values.

Returns:

  1. number r Red colour value.
  2. number g Green colour value.
  3. number b Blue colour value.
lightIntensity (intensity)
Sets the intensity of the main lights excluding ambient lighting. Multiplies the default radiosity values.

Parameters:

  • intensity number Intensity to set the lights to.
lightIntensityGet ()
Gets the light intensity.

Returns:

    number Light intensity.
glVersion ()
Gets the OpenGL version.

Returns:

  1. integer Major OpenGL version.
  2. integer Minor OpenGL version.
  3. integer GLSL version.
generated by LDoc 1.5.0 Last updated 2024-04-20 07:45:27