naev 0.12.6
nlua_tex.c File Reference

Handles the Lua texture bindings. More...

#include "physfsrwops.h"
#include "nlua_tex.h"
#include "ndata.h"
#include "nlua_data.h"
#include "nlua_file.h"
#include "nluadef.h"
#include "physics.h"
Include dependency graph for nlua_tex.c:

Go to the source code of this file.

Functions

static uint32_t get_pixel (SDL_Surface *surface, int x, int y)
static int texL_close (lua_State *L)
 Frees the texture.
static int texL_new (lua_State *L)
 Opens a texture.
static int texL_readData (lua_State *L)
 Reads image data from a file.
static int texL_writeData (lua_State *L)
 Saves texture data as a png.
static int texL_dim (lua_State *L)
 Gets the dimensions of the texture.
static int texL_sprites (lua_State *L)
 Gets the number of sprites in the texture.
static int texL_spriteFromDir (lua_State *L)
 Gets the sprite that corresponds to a direction.
static int texL_setFilter (lua_State *L)
 Sets the texture minification and magnification filters.
static int texL_setWrap (lua_State *L)
 Sets the texture wrapping.
int nlua_loadTex (nlua_env env)
 Loads the texture library.
glTexturelua_totex (lua_State *L, int ind)
 Lua bindings to interact with OpenGL textures.
glTextureluaL_checktex (lua_State *L, int ind)
 Gets texture at index or raises error if there is no texture at index.
glTextureluaL_validtex (lua_State *L, int ind, const char *searchpath)
 Gets texture directly or from a filename (string) at index or raises error if there is no texture at index.
glTexture ** lua_pushtex (lua_State *L, glTexture *texture)
 Pushes a texture on the stack.
int lua_istex (lua_State *L, int ind)
 Checks to see if ind is a texture.

Variables

static int nlua_tex_counter = 0
static const luaL_Reg texL_methods []

Detailed Description

Handles the Lua texture bindings.

Definition in file nlua_tex.c.

Function Documentation

◆ get_pixel()

uint32_t get_pixel ( SDL_Surface * surface,
int x,
int y )
inlinestatic

Definition at line 266 of file nlua_tex.c.

◆ lua_istex()

int lua_istex ( lua_State * L,
int ind )

Checks to see if ind is a texture.

Parameters
LLua state to check.
indIndex position to check.
Returns
1 if ind is a texture.

Definition at line 144 of file nlua_tex.c.

◆ lua_pushtex()

glTexture ** lua_pushtex ( lua_State * L,
glTexture * texture )

Pushes a texture on the stack.

Parameters
LLua state to push texture into.
textureTexture to push.
Returns
Newly pushed texture.

Definition at line 129 of file nlua_tex.c.

◆ lua_totex()

glTexture * lua_totex ( lua_State * L,
int ind )

Lua bindings to interact with OpenGL textures.

This will allow you to load textures.

An example would be:

t = tex.open( "foo/bar.png" ) -- Loads the texture
w,h, sw,sh = t:dim()
sprites, sx,sy = t:sprites()

Lua module: tex

Gets texture at index.

Parameters
LLua state to get texture from.
indIndex position to find the texture.
Returns
Texture found at the index in the state.

Definition at line 86 of file nlua_tex.c.

◆ luaL_checktex()

glTexture * luaL_checktex ( lua_State * L,
int ind )

Gets texture at index or raises error if there is no texture at index.

Parameters
LLua state to get texture from.
indIndex position to find texture.
Returns
Texture found at the index in the state.

Definition at line 97 of file nlua_tex.c.

◆ luaL_validtex()

glTexture * luaL_validtex ( lua_State * L,
int ind,
const char * searchpath )

Gets texture directly or from a filename (string) at index or raises error if there is no texture at index.

Parameters
LLua state to get texture from.
indIndex position to find texture.
searchpathPath to search for files.
Returns
Texture found at the index in the state.

Definition at line 113 of file nlua_tex.c.

◆ nlua_loadTex()

int nlua_loadTex ( nlua_env env)

Loads the texture library.

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

Definition at line 59 of file nlua_tex.c.

◆ texL_close()

int texL_close ( lua_State * L)
static

Frees the texture.

Lua function parameter: Tex t Texture to free.

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

Lua function: __gc

Definition at line 166 of file nlua_tex.c.

◆ texL_dim()

int texL_dim ( lua_State * L)
static

Gets the dimensions of the texture.

Lua usage parameter: w,h, sw,sh = t:dim()

Lua function parameter: Tex t Texture to get dimensions of. Lua return parameter: number The width the total image. Lua return parameter: number The height the total image. Lua return parameter: number The width the sprites. Lua return parameter: number The height the sprites.

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

Lua function: dim

Definition at line 427 of file nlua_tex.c.

◆ texL_new()

int texL_new ( lua_State * L)
static

Opens a texture.

Note
open( path, (sx=1), (sy=1) )
open( file, (sx=1), (sy=1) )
open( data, w, h, (sx=1), (sy=1) )

Lua usage parameter: t = tex.open( "no_sprites.png" ) Lua usage parameter: t = tex.open( "spritesheet.png", 6, 6 )

Lua function parameter: string|File|Data path Path, File, or Data to open. Lua function parameter:[opt=1] number w Width when Data or optional number of x sprites otherwise. Lua function parameter:[opt=1] number h Height when Data or optional number of y sprites otherwise. Lua function parameter:[opt=1] number sx Optional number of x sprites when path is Data. Lua function parameter:[opt=1] number sy Optional number of y sprites when path is Data. Lua return parameter: Tex The opened texture or nil on error.

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

Lua function: open

Definition at line 196 of file nlua_tex.c.

◆ texL_readData()

int texL_readData ( lua_State * L)
static

Reads image data from a file.

Lua function parameter: file File|string File or filename of the file to read the data from. Lua return parameter: Data Data containing the image data. Lua return parameter: number Width of the loaded data. Lua return parameter: number Height of the loaded data.

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

Lua function: readData

Definition at line 307 of file nlua_tex.c.

◆ texL_setFilter()

int texL_setFilter ( lua_State * L)
static

Sets the texture minification and magnification filters.

Lua function parameter: Tex tex Texture to set filter. Lua function parameter: string min Minification filter ("nearest" or "linear") Lua function parameter:[opt] string mag Magnification filter ("nearest" or "linear"). Defaults to min.

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

Lua function: setFilter

Definition at line 495 of file nlua_tex.c.

◆ texL_setWrap()

int texL_setWrap ( lua_State * L)
static

Sets the texture wrapping.

Lua function parameter: Tex tex Texture to set filter. Lua function parameter: string horiz Horizontal wrapping ("clamp", "repeat", or "mirroredrepeat" ) Lua function parameter:[opt] string vert Vertical wrapping ("clamp", "repeat", or "mirroredrepeat" ) Lua function parameter:[opt] string depth Depth wrapping ("clamp", "repeat", or "mirroredrepeat" )

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

Lua function: setWrap

Definition at line 529 of file nlua_tex.c.

◆ texL_spriteFromDir()

int texL_spriteFromDir ( lua_State * L)
static

Gets the sprite that corresponds to a direction.

Lua usage parameter: sx, sy = t:spriteFromDir( math.pi )

Lua function parameter: Tex t Texture to get sprite of. Lua function parameter: number a Direction to have sprite facing (in radians). Lua return parameter: number The x position of the sprite. Lua return parameter: number The y position of the sprite.

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

Lua function: spriteFromDir

Definition at line 470 of file nlua_tex.c.

◆ texL_sprites()

int texL_sprites ( lua_State * L)
static

Gets the number of sprites in the texture.

Lua usage parameter: sprites, sx,sy = t:sprites()

Lua function parameter: Tex t Texture to get sprites of. Lua return parameter: number The total number of sprites. Lua return parameter: number The number of X sprites. Lua return parameter: number The number of Y sprites.

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

Lua function: sprites

Definition at line 449 of file nlua_tex.c.

◆ texL_writeData()

int texL_writeData ( lua_State * L)
static

Saves texture data as a png.

Lua function parameter: Tex t Texture to convert to string. Lua return parameter: string Texture as a string.

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

Lua function: toData

Definition at line 373 of file nlua_tex.c.

Variable Documentation

◆ nlua_tex_counter

int nlua_tex_counter = 0
static

Definition at line 24 of file nlua_tex.c.

◆ texL_methods

const luaL_Reg texL_methods[]
static
Initial value:
= {
{ "__gc", texL_close },
{ "new", texL_new },
{ "open", texL_new },
{ "readData", texL_readData },
{ "writeData", texL_writeData },
{ "dim", texL_dim },
{ "sprites", texL_sprites },
{ "spriteFromDir", texL_spriteFromDir },
{ "setFilter", texL_setFilter },
{ "setWrap", texL_setWrap },
{ 0, 0 } }
static int texL_dim(lua_State *L)
Gets the dimensions of the texture.
Definition nlua_tex.c:427
static int texL_setWrap(lua_State *L)
Sets the texture wrapping.
Definition nlua_tex.c:529
static int texL_readData(lua_State *L)
Reads image data from a file.
Definition nlua_tex.c:307
static int texL_spriteFromDir(lua_State *L)
Gets the sprite that corresponds to a direction.
Definition nlua_tex.c:470
static int texL_new(lua_State *L)
Opens a texture.
Definition nlua_tex.c:196
static int texL_writeData(lua_State *L)
Saves texture data as a png.
Definition nlua_tex.c:373
static int texL_sprites(lua_State *L)
Gets the number of sprites in the texture.
Definition nlua_tex.c:449
static int texL_close(lua_State *L)
Frees the texture.
Definition nlua_tex.c:166
static int texL_setFilter(lua_State *L)
Sets the texture minification and magnification filters.
Definition nlua_tex.c:495

Texture metatable methods.

Definition at line 40 of file nlua_tex.c.