naev 0.12.5
nlua_gfx.c File Reference

Handles the rendering of graphics on the screen. More...

#include "nlua_gfx.h"
#include "array.h"
#include "font.h"
#include "gltf.h"
#include "nlua_canvas.h"
#include "nlua_colour.h"
#include "nlua_font.h"
#include "nlua_shader.h"
#include "nlua_tex.h"
#include "nlua_transform.h"
#include "nlua_vec2.h"
#include "nluadef.h"
#include "opengl.h"
#include "render.h"
Include dependency graph for nlua_gfx.c:

Go to the source code of this file.

Functions

static int gfxL_dim (lua_State *L)
 Lua bindings to interact with rendering and the Naev graphical environment.
static int gfxL_screencoords (lua_State *L)
 Gets the screen coordinates from game coordinates.
static int gfxL_renderTex (lua_State *L)
 Renders a texture.
static int gfxL_renderTexRaw (lua_State *L)
 Renders a texture using the core render function.
static int gfxL_renderTexScale (lua_State *L)
 DEPRECATED: Renders a texture, scaled. Ultimately, love.graphics should handle this.
static int gfxL_renderTexH (lua_State *L)
 Renders a texture using a transformation matrix.
static int gfxL_renderRect (lua_State *L)
 Renders a rectangle.
static int gfxL_renderRectH (lua_State *L)
 Renders a rectangle given a transformation matrix.
static int gfxL_renderCircle (lua_State *L)
 Renders a circle.
static int gfxL_renderCircleH (lua_State *L)
 Renders a circle given a transformation matrix.
static int gfxL_renderLinesH (lua_State *L)
 Renders a polyline or set of line segments.
static int gfxL_clearDepth (lua_State *L)
 Clears the depth buffer.
static int gfxL_fontSize (lua_State *L)
 Gets the size of the font.
static int gfxL_printfDim (lua_State *L)
 Gets the size of the text to print.
static int gfxL_printfEnd (lua_State *L)
 Gets the position at which text would end printing. Can be the middle of a line.
static int gfxL_printfWrap (lua_State *L)
 Gets the wrap for text.
static int gfxL_printRestoreClear (lua_State *L)
 Clears the saved internal colour state.
static int gfxL_printRestoreLast (lua_State *L)
 Restores the last saved internal colour state.
static int gfxL_printf (lua_State *L)
 Prints text on the screen using a font.
static int gfxL_printH (lua_State *L)
 Prints text on the screen using a font with a transformation matirx.
static int gfxL_printDim (lua_State *L)
 Gets the size of the text to print.
static int gfxL_print (lua_State *L)
 Prints text on the screen.
static int gfxL_printText (lua_State *L)
 Prints a block of text on the screen.
static int gfxL_setBlendMode (lua_State *L)
 Sets the OpenGL blending mode. See https://love2d.org/wiki/love.graphics.setBlendMode as of version 0.10.
static int gfxL_setBlendState (lua_State *L)
 Sets the OpenGL blending state. See https://love2d.org/wiki/love.graphics.setBlendState as of version 0.12.
static int gfxL_setScissor (lua_State *L)
 Sets the scissor clipping.
static int gfxL_lightAmbient (lua_State *L)
 Sets the ambient lighting.
static int gfxL_lightAmbientGet (lua_State *L)
 Gets the ambient lighting values.
static int gfxL_lightIntensity (lua_State *L)
 Sets the intensity of the main lights excluding ambient lighting. Multiplies the default radiosity values.
static int gfxL_lightIntensityGet (lua_State *L)
 Gets the light intensity.
static int gfxL_screenshot (lua_State *L)
 Takes the current rendered game screen and returns it as a canvas.
static int gfxL_glVersion (lua_State *L)
 Gets the OpenGL version.
int nlua_loadGFX (nlua_env env)
 Loads the graphics library.

Variables

static const luaL_Reg gfxL_methods []
static gl_vbo * vbo_lines = NULL

Detailed Description

Handles the rendering of graphics on the screen.

Definition in file nlua_gfx.c.

Function Documentation

◆ gfxL_clearDepth()

int gfxL_clearDepth ( lua_State * L)
static

Clears the depth buffer.

Definition at line 638 of file nlua_gfx.c.

◆ gfxL_dim()

int gfxL_dim ( lua_State * L)
static

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

Lua module: gfx

Gets the dimensions of the Naev window.

Lua usage parameter: screen_w, screen_h = gfx.dim()

Lua function parameter:[opt=false] boolean guisize Whether or not to consider the GUI modifications to the screen size. Lua return parameter: number The width of the Naev window. Lua return parameter: number The height of the Naev window. Lua return parameter: scale The scaling factor.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: dim

Definition at line 154 of file nlua_gfx.c.

◆ gfxL_fontSize()

int gfxL_fontSize ( lua_State * L)
static

Gets the size of the font.

Lua function parameter: boolean small Whether or not to get the size of the small font. Lua return parameter:[opt=false] The size in pixels of the font.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: fontSize

Definition at line 654 of file nlua_gfx.c.

◆ gfxL_glVersion()

int gfxL_glVersion ( lua_State * L)
static

Gets the OpenGL version.

Lua return parameter: integer Major OpenGL version. Lua return parameter: integer Minor OpenGL version. Lua return parameter: integer GLSL version.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: glVersion

Definition at line 1246 of file nlua_gfx.c.

◆ gfxL_lightAmbient()

int gfxL_lightAmbient ( lua_State * L)
static

Sets the ambient lighting.

Lua function parameter: Colour|number r 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. Lua function parameter:[opt=r] number g Green channel to use for ambient lighting. Lua function parameter:[opt=r] number b Blue channel to use for ambient lighting. Lua function parameter:[opt] number strength 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.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: lightAmbient

Definition at line 1169 of file nlua_gfx.c.

◆ gfxL_lightAmbientGet()

int gfxL_lightAmbientGet ( lua_State * L)
static

Gets the ambient lighting values.

Lua return parameter: number r Red colour value. Lua return parameter: number g Green colour value. Lua return parameter: number b Blue colour value.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: lightAmbientGet

Definition at line 1203 of file nlua_gfx.c.

◆ gfxL_lightIntensity()

int gfxL_lightIntensity ( lua_State * L)
static

Sets the intensity of the main lights excluding ambient lighting. Multiplies the default radiosity values.

Lua function parameter: number intensity Intensity to set the lights to.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: lightIntensity

Definition at line 1220 of file nlua_gfx.c.

◆ gfxL_lightIntensityGet()

int gfxL_lightIntensityGet ( lua_State * L)
static

Gets the light intensity.

Lua return parameter: number Light intensity.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: lightIntensityGet

Definition at line 1232 of file nlua_gfx.c.

◆ gfxL_print()

int gfxL_print ( lua_State * L)
static

Prints text on the screen.

Lua usage parameter: gfx.print( nil, _("Hello World!"), 50, 50, colour.new("Red") ) – Displays text in red at 50,50. Lua usage parameter: gfx.print( true, _("Hello World!"), 50, 50, col, 100 ) – Displays text to a maximum of 100 pixels wide. Lua usage parameter: gfx.print( true, str, 50, 50, col, 100, true ) – Displays centered text to a maximum of 100 pixels.

Lua function parameter: boolean small Whether or not to use a small font. Lua function parameter: string str String to print. Lua function parameter: number x X position to print at. Lua function parameter: number y Y position to print at. Lua function parameter: Colour col Colour to print text. Lua function parameter:[opt] int max Maximum width to render up to. Lua function parameter:[opt] boolean center Whether or not to center it.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: print

Definition at line 915 of file nlua_gfx.c.

◆ gfxL_printDim()

int gfxL_printDim ( lua_State * L)
static

Gets the size of the text to print.

Lua usage parameter: len = gfx.printDim( nil, _("Hello World!") ) – Length of string with normal font Lua usage parameter: height = gfx.printDim( true, _([["Longer text"]]), 20 ) – Dimensions of text block

Lua function parameter: boolean small Whether or not to use the small font. Lua function parameter: string str Text to calculate length of. Lua function parameter:[opt] int width Optional parameter to indicate it is a block of text and to use this width.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: printDim

Definition at line 675 of file nlua_gfx.c.

◆ gfxL_printf()

int gfxL_printf ( lua_State * L)
static

Prints text on the screen using a font.

Lua usage parameter: gfx.printf( font, _("Hello World!"), 50, 50, colour.new("Red") ) – Displays text in red at 50,50.

Lua function parameter: font font Font to use. Lua function parameter: string str String to print. Lua function parameter: number x X position to print at. Lua function parameter: number y Y position to print at. Lua function parameter: Colour col Colour to print text. Lua function parameter:[opt] int max Maximum width to render up to. Lua function parameter:[opt] boolean center Whether or not to center it.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: printf

Definition at line 839 of file nlua_gfx.c.

◆ gfxL_printfDim()

int gfxL_printfDim ( lua_State * L)
static

Gets the size of the text to print.

Lua function parameter: font font Font to use. Lua function parameter: string str Text to calculate length of. Lua function parameter:[opt] int width Optional parameter to indicate it is a block of text and to use this width. Lua return parameter: number The width or height (if width is not set) of the text.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: printfDim

Definition at line 704 of file nlua_gfx.c.

◆ gfxL_printfEnd()

int gfxL_printfEnd ( lua_State * L)
static

Gets the position at which text would end printing. Can be the middle of a line.

Lua function parameter: font font Font to use. Lua function parameter: string str Text to calculate length of. Lua function parameter: int width Maximum width to use for the text. Lua return parameter: number The x coordinate it ended printing at. Lua return parameter: number The y coordinate it ended up printing at.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: printfEnd

Definition at line 734 of file nlua_gfx.c.

◆ gfxL_printfWrap()

int gfxL_printfWrap ( lua_State * L)
static

Gets the wrap for text.

Lua function parameter: font font Font to use. Lua function parameter: string str Text to calculate length of. Lua function parameter: int width Width to wrap at. Lua return parameter: table A table containing pairs of text and their width. Lua return parameter: number Maximum width of all the lines.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: printfWrap

Definition at line 763 of file nlua_gfx.c.

◆ gfxL_printH()

int gfxL_printH ( lua_State * L)
static

Prints text on the screen using a font with a transformation matirx.

Lua function parameter: Transform H transformation matrix to use. Lua function parameter: font font Font to use. Lua function parameter: string str String to print. Lua function parameter:[opt=white] Colour col Colour to print text. Lua function parameter:[opt=0] number outline How big to make an outline.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: printH

Definition at line 876 of file nlua_gfx.c.

◆ gfxL_printRestoreClear()

int gfxL_printRestoreClear ( lua_State * L)
static

Clears the saved internal colour state.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: printRestoreClear

Definition at line 806 of file nlua_gfx.c.

◆ gfxL_printRestoreLast()

int gfxL_printRestoreLast ( lua_State * L)
static

Restores the last saved internal colour state.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: printRestoreLast

Definition at line 817 of file nlua_gfx.c.

◆ gfxL_printText()

int gfxL_printText ( lua_State * L)
static

Prints a block of text on the screen.

Lua usage parameter: gfx.printText( true, 100, 50, 50, 100, 100, col ) – Displays a 100x100 block of text

Lua function parameter: boolean small Whether or not to use a small font. Lua function parameter: string str String to print. Lua function parameter: number x X position to print at. Lua function parameter: number y Y position to print at. Lua function parameter: number w Width of the block of text. Lua function parameter: number h Height of the block of text. Lua function parameter: Colour col Colour to print text. Lua function parameter: line_height Height of each line to print.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: printText

Definition at line 958 of file nlua_gfx.c.

◆ gfxL_renderCircle()

int gfxL_renderCircle ( lua_State * L)
static

Renders a circle.

Lua function parameter: number x X position to render at. Lua function parameter: number y Y position to render at. Lua function parameter: number r Radius of the circle. Lua function parameter: Colour col Colour to use. Lua function parameter:[opt=false] boolean empty Whether or not it should be empty.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: renderCircle

Definition at line 531 of file nlua_gfx.c.

◆ gfxL_renderCircleH()

int gfxL_renderCircleH ( lua_State * L)
static

Renders a circle given a transformation matrix.

Lua function parameter: Transform H Transformation matrix to use. Lua function parameter:[opt=white] Colour col Colour to use. Lua function parameter:[opt=false] boolean empty Whether or not it should be empty.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: renderCircleH

Definition at line 557 of file nlua_gfx.c.

◆ gfxL_renderLinesH()

int gfxL_renderLinesH ( lua_State * L)
static

Renders a polyline or set of line segments.

Lua usage parameter: gfx.renderLinesH( 50,30, 70,70 ) Lua usage parameter: gfx.renderLinesH( vec2.new(), vec2.new(100,100), vec2.new(200,100) )

Lua function parameter: Transform H Transform to use when rendering. Lua function parameter: Colour Colour to use when drawing. Lua function parameter: number|Vec2 Either a set of x/y coordinates or 2D vector.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: renderLinesH

Definition at line 581 of file nlua_gfx.c.

◆ gfxL_renderRect()

int gfxL_renderRect ( lua_State * L)
static

Renders a rectangle.

Lua usage parameter: gfx.renderRect( 10., 30,. 40., 40., col ) – Renders a 40 side square at position 10,30 of colour col Lua usage parameter: gfx.renderRect( 10., 30,. 40., 40., col, True ) – Renders a 40 side empty square at position 10,30 of colour col

Lua function parameter: number x X position to render at. Lua function parameter: number y Y position to render at. Lua function parameter: number w Width of the rectangle. Lua function parameter: number h Height of the rectangle. Lua function parameter: Colour col Colour to use. Lua function parameter:[opt=false] boolean empty Whether or not it should be empty.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: renderRect

Definition at line 477 of file nlua_gfx.c.

◆ gfxL_renderRectH()

int gfxL_renderRectH ( lua_State * L)
static

Renders a rectangle given a transformation matrix.

Lua function parameter: Transform H Transformation matrix to use. Lua function parameter:[opt=white] Colour col Colour to use. Lua function parameter:[opt=false] boolean empty Whether or not it should be empty.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: renderRectH

Definition at line 508 of file nlua_gfx.c.

◆ gfxL_renderTex()

int gfxL_renderTex ( lua_State * L)
static

Renders a texture.

This function has variable parameters depending on how you want to render.

Lua usage parameter: gfx.renderTex( tex, 0., 0. ) – Render tex at origin Lua usage parameter: gfx.renderTex( tex, 0., 0., col ) – Render tex at origin with colour col Lua usage parameter: gfx.renderTex( tex, 0., 0., 4, 3 ) – Render sprite at position 4,3 (top-left is 1,1) Lua usage parameter: gfx.renderTex( tex, 0., 0., 4, 3, col ) – Render sprite at position 4,3 (top-left is 1,1) with colour col

Lua function parameter: Tex tex Texture to render. Lua function parameter: number pos_x X position to render texture at. Lua function parameter: number pos_y Y position to render texture at. Lua function parameter:[opt=0] int sprite_x X sprite to render. Lua function parameter:[opt=0] int sprite_y Y sprite to render. Lua function parameter:[opt] Colour colour Colour to use when rendering.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: renderTex

Definition at line 210 of file nlua_gfx.c.

◆ gfxL_renderTexH()

int gfxL_renderTexH ( lua_State * L)
static

Renders a texture using a transformation matrix.

Lua function parameter: Tex tex Texture to render. Lua function parameter: Shader shader Shader to use when rendering. Lua function parameter: Transformation H Transformation matrix to use. Lua function parameter:[opt=white] Colour colour Colour to use or white if not set.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: renderTexH

Definition at line 398 of file nlua_gfx.c.

◆ gfxL_renderTexRaw()

int gfxL_renderTexRaw ( lua_State * L)
static

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.

Lua usage parameter: 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.

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

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: renderTexRaw

Definition at line 338 of file nlua_gfx.c.

◆ gfxL_renderTexScale()

int gfxL_renderTexScale ( lua_State * L)
static

DEPRECATED: Renders a texture, scaled. Ultimately, love.graphics should handle this.

Lua function parameter: Tex tex Texture to render. Lua function parameter: number pos_x X position to render texture at. Lua function parameter: number pos_y Y position to render texture at. Lua function parameter: number bw Width to scale to. Lua function parameter: number bh Height to scale to. Lua function parameter:[opt=0] int sprite_x X sprite to render. Lua function parameter:[opt=0] int sprite_y Y sprite to render. Lua function parameter:[opt] Colour colour Colour to use when rendering.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: renderTexScale

Definition at line 265 of file nlua_gfx.c.

◆ gfxL_screencoords()

int gfxL_screencoords ( lua_State * L)
static

Gets the screen coordinates from game coordinates.

Lua function parameter: Vec2 Vector of coordinates to transnform. Lua function parameter:[opt=false] boolean Whether or not to invert y axis. Lua return parameter: Vec2 Transformed vector.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: screencoords

Definition at line 175 of file nlua_gfx.c.

◆ gfxL_screenshot()

int gfxL_screenshot ( lua_State * L)
static

Takes the current rendered game screen and returns it as a canvas.

Lua function parameter:[opt=nil] Canvas c Canvas to use instead of creating a new one. Lua return parameter: Canvas A new canvas or parameter canvas if available with the screen data in it.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: screenshot

Definition at line 1123 of file nlua_gfx.c.

◆ gfxL_setBlendMode()

int gfxL_setBlendMode ( lua_State * L)
static

Sets the OpenGL blending mode. See https://love2d.org/wiki/love.graphics.setBlendMode as of version 0.10.

Lua usage parameter: gfx.setBlendMode( "alpha", "premultiplied" )

Lua function parameter: string mode One of: "alpha", "replace", "screen", "add", "subtract", "multiply", "lighten", or "darken". Lua function parameter:[opt="alphamultiply"] string alphamode Override to "premultiplied" when drawing canvases; see https://love2d.org/wiki/BlendAlphaMode.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setBlendMode

Definition at line 995 of file nlua_gfx.c.

◆ gfxL_setBlendState()

int gfxL_setBlendState ( lua_State * L)
static

Sets the OpenGL blending state. See https://love2d.org/wiki/love.graphics.setBlendState as of version 0.12.

Lua usage parameter: gfx.setBlendState( "add", "src_alpha", "one_minus_src_alpha" )

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setBlendState

Definition at line 1056 of file nlua_gfx.c.

◆ gfxL_setScissor()

int gfxL_setScissor ( lua_State * L)
static

Sets the scissor clipping.

Calling setScissor with no parameters disables the clipping.

Lua function parameter: number x X position of the clipping rectangle. Lua function parameter: number y Y position of the clipping rectangle. Lua function parameter: number width Width of the clipping rectangle. Lua function parameter: number height Height of the clipping rectangle.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setScissor

Definition at line 1097 of file nlua_gfx.c.

◆ nlua_loadGFX()

int nlua_loadGFX ( nlua_env env)

Loads the graphics library.

Parameters
envEnvironment to load graphics library into.
Returns
0 on success.

Definition at line 112 of file nlua_gfx.c.

Variable Documentation

◆ gfxL_methods

const luaL_Reg gfxL_methods[]
static

GFX methods.

Definition at line 66 of file nlua_gfx.c.

◆ vbo_lines

gl_vbo* vbo_lines = NULL
static

Definition at line 569 of file nlua_gfx.c.