20#include "nlua_colour.h"
22#include "nlua_shader.h"
24#include "nlua_transform.h"
25#include "nlua_canvas.h"
109 nlua_loadCanvas( env );
139 if (lua_isboolean(L,1)) {
140 lua_pushnumber( L, SCREEN_W );
141 lua_pushnumber( L, SCREEN_H );
164 int invert = lua_toboolean( L, 2 );
168 vec2_cset( &screen, x, y );
200 x = luaL_checknumber( L, 2 );
201 y = luaL_checknumber( L, 3 );
202 if (lua_isnumber( L, 4 )) {
203 sx = luaL_checkinteger( L, 4 )-1;
204 sy = luaL_checkinteger( L, 5 )-1;
205 col = luaL_optcolour( L, 6, &cWhite );
210 col = luaL_optcolour( L, 4, &cWhite );
215 if (sx < 0 || sx >= tex->
sx)
216 return NLUA_ERROR( L, _(
"Texture '%s' trying to render out of bounds (X position) sprite: %d > %d."),
217 tex->
name, sx+1, tex->
sx );
218 if (sy < 0 || sy >= tex->
sy)
219 return NLUA_ERROR( L, _(
"Texture '%s' trying to render out of bounds (Y position) sprite: %d > %d."),
220 tex->
name, sy+1, tex->
sy );
252 x = luaL_checknumber( L, 2 );
253 y = luaL_checknumber( L, 3 );
254 bw = luaL_checknumber( L, 4 );
255 bh = luaL_checknumber( L, 5 );
256 if (lua_isnumber( L, 6 )) {
257 sx = luaL_checkinteger( L, 6 ) - 1;
258 sy = luaL_checkinteger( L, 7 ) - 1;
272 return NLUA_ERROR( L, _(
"Texture '%s' trying to render out of bounds (X position) sprite: %d > %d."),
273 tex->
name, sx+1, tex->
sx );
275 return NLUA_ERROR( L, _(
"Texture '%s' trying to render out of bounds (Y position) sprite: %d > %d."),
276 tex->
name, sy+1, tex->
sy );
313 double px,py, pw,ph, tx,ty, tw,th;
319 px = luaL_checknumber( L, 2 );
320 py = luaL_checknumber( L, 3 );
321 pw = luaL_checknumber( L, 4 );
322 ph = luaL_checknumber( L, 5 );
323 sx = luaL_optinteger( L, 6, 1 ) - 1;
324 sy = luaL_optinteger( L, 7, 1 ) - 1;
325 tx = luaL_optnumber( L, 8, 0. );
326 ty = luaL_optnumber( L, 9, 0. );
327 tw = luaL_optnumber( L, 10, 1. );
328 th = luaL_optnumber( L, 11, 1. );
329 col = luaL_optcolour(L, 12, &cWhite );
330 angle = luaL_optnumber(L,13,0.);
335 return NLUA_ERROR( L, _(
"Texture '%s' trying to render out of bounds (X position) sprite: %d > %d."),
338 return NLUA_ERROR( L, _(
"Texture '%s' trying to render out of bounds (Y position) sprite: %d > %d."),
343 tx = (tx * t->
sw + t->
sw * (double)(sx)) / t->
w;
347 ty = (ty * t->
sh + t->
sh * (t->
sy - (double)sy-1)) / t->
h;
352 gl_renderTexture( t, px, py, pw, ph, tx, ty, tw, th, col, angle );
378 col = luaL_optcolour(L,4,&cWhite);
379 TH = luaL_opttransform( L,5,&ID );
381 glUseProgram( shader->program );
384 glEnableVertexAttribArray( shader->VertexPosition );
389 if (shader->VertexTexCoord >= 0) {
390 gl_uniformMat4( shader->ViewSpaceFromLocal, TH );
391 glEnableVertexAttribArray( shader->VertexTexCoord );
397 glBindTexture( GL_TEXTURE_2D, t->
texture );
398 glUniform1i( shader->MainTex, 0 );
399 for (
int i=0; i<
array_size(shader->tex); i++) {
401 glActiveTexture( lt->active );
402 glBindTexture( GL_TEXTURE_2D, lt->texid );
403 glUniform1i( lt->uniform, lt->value );
405 glActiveTexture( GL_TEXTURE0 );
408 gl_uniformColour( shader->ConstantColour, col );
409 gl_uniformMat4( shader->ClipSpaceFromLocal, H );
412 glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
415 glDisableVertexAttribArray( shader->VertexPosition );
416 if (shader->VertexTexCoord >= 0)
417 glDisableVertexAttribArray( shader->VertexTexCoord );
448 x = luaL_checknumber( L, 1 );
449 y = luaL_checknumber( L, 2 );
450 w = luaL_checknumber( L, 3 );
451 h = luaL_checknumber( L, 4 );
453 empty = lua_toboolean( L, 6 );
476 const glColour *col = luaL_optcolour(L,2,&cWhite);
477 int empty = lua_toboolean(L,3);
502 x = luaL_checknumber( L, 1 );
503 y = luaL_checknumber( L, 2 );
504 r = luaL_checknumber( L, 3 );
506 empty = lua_toboolean( L, 5 );
527 const glColour *col = luaL_optcolour(L,2,&cWhite);
528 int empty = lua_toboolean(L,3);
536static gl_vbo *vbo_lines = NULL;
554 const glColour *
c = luaL_optcolour(L,2,&cWhite);
559 while (!lua_isnoneornil(L,i)) {
561 WARN(_(
"Trying to draw too many lines in one call!"));
566 if (lua_isnumber(L,i)) {
567 double x = luaL_checknumber(L,i);
568 double y = luaL_checknumber(L,i+1);
583 glUseProgram(shaders.lines.program);
585 gl_vboData( vbo_lines,
sizeof(GLfloat)*2*n, buf );
586 glEnableVertexAttribArray( shaders.lines.vertex );
588 2, GL_FLOAT, 2*
sizeof(GLfloat) );
590 gl_uniformColour(shaders.lines.colour,
c);
591 gl_uniformMat4(shaders.lines.projection, H);
593 glDrawArrays( GL_LINE_STRIP, 0, n );
608 glClear( GL_DEPTH_BUFFER_BIT );
621 int small = lua_toboolean(L,1);
645 str = luaL_checkstring(L,2);
646 width = luaL_optinteger(L,3,0);
672 str = luaL_checkstring(L,2);
673 width = luaL_optinteger(L,3,0);
703 s = luaL_checkstring(L,2);
704 width = luaL_checkinteger(L,3);
706 return NLUA_ERROR(L,_(
"width has to be a positive value."));
718 lua_pushlstring(L, &s[iter.l_begin], iter.
l_end - iter.l_begin);
720 lua_pushinteger(L,iter.
l_width);
722 lua_rawseti(L,-2,linenum++);
726 lua_pushinteger(L, maxw);
777 str = luaL_checkstring(L,2);
778 x = luaL_checknumber(L,3);
779 y = luaL_checknumber(L,4);
781 max = luaL_optinteger(L,6,0);
782 mid = lua_toboolean(L,7);
815 str = luaL_checkstring(L,3);
816 col = luaL_optcolour(L,4,&cWhite);
817 outline = luaL_optnumber(L,5,0.);
850 str = luaL_checkstring(L,2);
851 x = luaL_checknumber(L,3);
852 y = luaL_checknumber(L,4);
854 max = luaL_optinteger(L,6,0);
855 mid = lua_toboolean(L,7);
892 str = luaL_checkstring(L,2);
893 x = luaL_checknumber(L,3);
894 y = luaL_checknumber(L,4);
895 w = luaL_checkinteger(L,5);
896 h = luaL_checkinteger(L,6);
898 lh = luaL_optinteger(L,8,0);
917 const char *mode, *alphamode;
918 GLenum func, srcRGB, srcA, dstRGB, dstA;
921 mode = luaL_checkstring(L,1);
922 alphamode= luaL_optstring(L,2,
"alphamultiply");
931 if (!strcmp( alphamode,
"alphamultiply" ))
932 srcRGB = srcA = GL_SRC_ALPHA;
933 else if (!strcmp( alphamode,
"premultiplied" )) {
934 if (!strcmp( mode,
"lighten" ) || !strcmp( mode,
"darken" ) || !strcmp( mode,
"multiply" ))
935 NLUA_INVALID_PARAMETER(L,2);
938 NLUA_INVALID_PARAMETER(L,2);
940 if (!strcmp( mode,
"alpha" ))
941 dstRGB = dstA = GL_ONE_MINUS_SRC_ALPHA;
942 else if (!strcmp( mode,
"multiply" ))
943 srcRGB = srcA = GL_DST_COLOR;
944 else if (!strcmp( mode,
"subtract" ))
945 func = GL_FUNC_REVERSE_SUBTRACT;
946 else if (!strcmp( mode,
"add" ) ) {
947 func = GL_FUNC_REVERSE_SUBTRACT;
949 dstRGB = dstA = GL_ONE;
951 else if (!strcmp( mode,
"lighten" ))
953 else if (!strcmp( mode,
"darken" ))
955 else if (!strcmp( mode,
"screen" ))
956 dstRGB = dstA = GL_ONE_MINUS_SRC_COLOR;
957 else if (strcmp( mode,
"replace" ))
958 NLUA_INVALID_PARAMETER(L,1);
960 glBlendEquation(func);
961 glBlendFuncSeparate(srcRGB, dstRGB, srcA, dstA);
981 if (lua_gettop(L)>0) {
982 GLint x = luaL_optinteger(L,1,0);
983 GLint y = luaL_optinteger(L,2,0);
984 GLsizei w = luaL_optinteger(L,3,0);
985 GLsizei h = luaL_optinteger(L,4,0);
1008 if (lua_iscanvas(L,1)) {
1009 lc = luaL_checkcanvas(L,1);
1019 glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
1020 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, lc->
fbo);
1023 glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
1024 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
1027 lua_pushcanvas(L, *lc);
Provides macros to work with dynamic arrays.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
int gl_printHeightRaw(const glFont *ft_font, const int width, const char *text)
Gets the height of a non-formatted string.
void gl_printRestoreClear(void)
Clears the restoration.
int gl_printLineIteratorNext(glPrintLineIterator *iter)
Updates iter with the next line's information.
void gl_printRaw(const glFont *ft_font, double x, double y, const glColour *c, double outlineR, const char *text)
Prints text on screen.
int gl_printWidthRaw(const glFont *ft_font, const char *text)
Gets the width that it would take to print some text.
int gl_printMidRaw(const glFont *ft_font, int width, double x, double y, const glColour *c, double outlineR, const char *text)
Displays text centered in position and width.
int gl_printTextRaw(const glFont *ft_font, const int width, const int height, double bx, double by, int line_height, const glColour *c, double outlineR, const char *text)
Prints a block of text that fits in the dimensions given.
void gl_printRawH(const glFont *ft_font, const mat4 *H, const glColour *c, const double outlineR, const char *text)
Prints text on screen using a transformation matrix.
void gl_printLineIteratorInit(glPrintLineIterator *iter, const glFont *ft_font, const char *text, int width)
Initialize an iterator object for breaking text into lines.
int gl_printMaxRaw(const glFont *ft_font, const int max, double x, double y, const glColour *c, double outlineR, const char *text)
Behaves like gl_printRaw but stops displaying text after a certain distance.
void gl_printRestoreLast(void)
Restores last colour.
mat4 mat4_identity(void)
Creates an identity matrix.
Header file with generic functions and naev-specifics.
int lua_iscolour(lua_State *L, int ind)
Checks to see if ind is a colour.
int nlua_loadCol(nlua_env env)
Loads the colour library.
glColour * luaL_checkcolour(lua_State *L, int ind)
Gets colour at index or raises error if there is no colour at index.
int nlua_loadFont(nlua_env env)
Loads the font library.
glFont * luaL_checkfont(lua_State *L, int ind)
Gets font at index or raises error if there is no font at index.
static int gfxL_renderTexScale(lua_State *L)
DEPRECATED: Renders a texture, scaled. Ultimately, love.graphics should handle this.
static int gfxL_renderRectH(lua_State *L)
Renders a rectangle given a transformation matrix.
static int gfxL_screencoords(lua_State *L)
Gets the screen coordinates from game coordinates.
static int gfxL_dim(lua_State *L)
Lua bindings to interact with rendering and the Naev graphical environment.
static int gfxL_renderRect(lua_State *L)
Renders a rectangle.
static const luaL_Reg gfxL_methods[]
static int gfxL_printText(lua_State *L)
Prints a block of text on the screen.
static int gfxL_printf(lua_State *L)
Prints text on the screen using a font.
static int gfxL_screenshot(lua_State *L)
Takes the current rendered game screen and returns it as a canvas.
static int gfxL_renderTexH(lua_State *L)
Renders a texture using a transformation matrix.
static int gfxL_renderTex(lua_State *L)
Renders a texture.
static int gfxL_printfWrap(lua_State *L)
Gets the wrap for text.
static int gfxL_printfDim(lua_State *L)
Gets the size of the text to print.
static int gfxL_clearDepth(lua_State *L)
Clears the depth buffer.
static int gfxL_setBlendMode(lua_State *L)
Sets the OpenGL blending mode. See https://love2d.org/wiki/love.graphics.setBlendMode as of version 0...
static int gfxL_renderLinesH(lua_State *L)
Renders a polyline or set of line segments.
static int gfxL_renderCircle(lua_State *L)
Renders a circle.
static int gfxL_printRestoreLast(lua_State *L)
Restores the last saved internal colour state.
static int gfxL_printH(lua_State *L)
Prints text on the screen using a font with a transformation matirx.
int nlua_loadGFX(nlua_env env)
Loads the graphics library.
static int gfxL_renderCircleH(lua_State *L)
Renders a circle given a transformation matrix.
static int gfxL_fontSize(lua_State *L)
Gets the size of the font.
static int gfxL_renderTexRaw(lua_State *L)
Renders a texture using the core render function.
static int gfxL_printDim(lua_State *L)
Gets the size of the text to print.
static int gfxL_printRestoreClear(lua_State *L)
Clears the saved internal colour state.
static int gfxL_print(lua_State *L)
Prints text on the screen.
static int gfxL_setScissor(lua_State *L)
Sets the scissor clipping.
int nlua_loadShader(nlua_env env)
Loads the shader library.
LuaShader_t * luaL_checkshader(lua_State *L, int ind)
Gets shader at index or raises error if there is no shader at index.
glTexture * luaL_checktex(lua_State *L, int ind)
Gets texture at index or raises error if there is no texture at index.
int nlua_loadTex(nlua_env env)
Loads the texture library.
vec2 * luaL_checkvector(lua_State *L, int ind)
Gets vector at index making sure type is valid.
vec2 * lua_pushvector(lua_State *L, vec2 vec)
Pushes a vector on the stack.
void gl_renderRect(double x, double y, double w, double h, const glColour *c)
Renders a rectangle.
void gl_gameToScreenCoords(double *nx, double *ny, double bx, double by)
Converts in-game coordinates to screen coordinates.
void gl_renderCircleH(const mat4 *H, const glColour *c, int filled)
Draws a circle.
void gl_renderTexture(const glTexture *texture, double x, double y, double w, double h, double tx, double ty, double tw, double th, const glColour *c, double angle)
Texture blitting backend.
void gl_unclipRect(void)
Clears the 2d clipping planes.
void gl_renderScaleSprite(const glTexture *sprite, double bx, double by, int sx, int sy, double bw, double bh, const glColour *c)
Blits a scaled sprite, position is in absolute screen coordinates.
void gl_renderStaticSprite(const glTexture *sprite, double bx, double by, int sx, int sy, const glColour *c)
Blits a sprite, position is in absolute screen coordinates.
void gl_renderRectEmpty(double x, double y, double w, double h, const glColour *c)
Renders a rectangle.
void gl_renderRectH(const mat4 *H, const glColour *c, int filled)
Renders a rectangle.
void gl_clipRect(int x, int y, int w, int h)
Sets up 2d clipping planes around a rectangle.
void gl_renderCircle(double cx, double cy, double r, const glColour *c, int filled)
Draws a circle.
gl_vbo * gl_vboCreateDynamic(GLsizei size, const void *data)
Creates a dynamic vbo.
void gl_vboActivateAttribOffset(gl_vbo *vbo, GLuint index, GLuint offset, GLint size, GLenum type, GLsizei stride)
Activates a VBO's offset.
void gl_vboData(gl_vbo *vbo, GLsizei size, const void *data)
Reloads new data or grows the size of the vbo.
Represents a font in memory.
The state of a line iteration. This matches the process of rendering text into an on-screen box: An e...
Abstraction for rendering sprite sheets.