/** * @brief Gets colour at index or raises error if there is no colour at index. * * @param L Lua state to get colour from. * @param ind Index position to find colour. * @return Colour found at the index in the state. */ LuaColour* luaL_checkcolour( lua_State *L, int ind ) { if (lua_iscolour(L,ind)) return lua_tocolour(L,ind); luaL_typerror(L, ind, COL_METATABLE); return NULL; }
/** * @brief Adds a background image. * * If the colour parameter is a boolean it's treated as the foreground parameter instead. * * @usage bkg.image( img, 0, 0, 0.1, 1. ) -- Adds the image without scaling that moves at 0.1 the player speed * @usage bkg.image( img, 0, 0, 0.1, 1., true ) -- Now on the foreground * @usage bkg.image( img, 0, 0, 0.1, 1., col.new(1,0,0) ) -- Now with colour * @usage bkg.image( img, 0, 0, 0.1, 1., col.new(1,0,0), true ) -- Now with colour and on the foreground * * @luaparam image Image to use. * @luaparam x X position. * @luaparam y Y position. * @luaparam move Fraction of a pixel to move when the player moves one pixel. * @luaparam scale How much to scale the image. * @luaparam col Colour to tint image (optional parameter). * @luaparam foreground Whether or not it should be rendered above the stars (optional parameter ). Defaults to false. * @luareturn ID of the background. * @luafunc image( image, x, y, move, scale, col, foreground ) */ static int bkgL_image( lua_State *L ) { glTexture *tex; double x,y, move, scale; const glColour *col; unsigned int id; int foreground; /* Parse parameters. */ tex = luaL_checktex(L,1); x = luaL_checknumber(L,2); y = luaL_checknumber(L,3); move = luaL_checknumber(L,4); scale = luaL_checknumber(L,5); if (lua_iscolour(L,6)) { col = lua_tocolour(L,6); foreground = lua_toboolean(L,7); } else { col = &cWhite; foreground = lua_toboolean(L,6); } /* Create image. */ id = background_addImage( tex, x, y, move, scale, col, foreground ); lua_pushnumber(L,id); return 1; }
/** * @brief 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. * * @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. * * @luaparam tex Texture to render. * @luaparam pos_x X position to render texture at. * @luaparam pos_y Y position to render texture at. * @luaparam pos_w Width of the image on screen. * @luaparam pos_h Height of the image on screen. * @luaparam sprite_x X sprite to render. * @luaparam sprite_y Y sprite to render. * @luaparam tex_x X sprite texture offset as [0.:1.]. * @luaparam tex_y Y sprite texture offset as [0.:1.]. * @luaparam tex_w Sprite width to display as [-1.:1.]. Note if negative, it will flip the image horizontally. * @luaparam tex_h Sprite height to display as [-1.:1.] Note if negative, it will flip the image vertically. * @luaparam colour [OPTIONAL] Colour to use when rendering. * @luafunc renderTexRaw( tex, pos_x, pos_y, pos_w, pos_h, sprite_x, sprite_y, tex_x, tex_y, tex_w, tex_h, colour ) */ static int gfxL_renderTexRaw( lua_State *L ) { glTexture *t; LuaTex *lt; LuaColour *lc; double px,py, pw,ph, tx,ty, tw,th; int sx, sy; /* Parameters. */ lc = NULL; lt = luaL_checktex( L, 1 ); px = luaL_checknumber( L, 2 ); py = luaL_checknumber( L, 3 ); pw = luaL_checknumber( L, 4 ); ph = luaL_checknumber( L, 5 ); sx = luaL_checkinteger( L, 6 ) - 1; sy = luaL_checkinteger( L, 7 ) - 1; tx = luaL_checknumber( L, 8 ); ty = luaL_checknumber( L, 9 ); tw = luaL_checknumber( L, 10 ); th = luaL_checknumber( L, 11 ); if (lua_iscolour( L, 12 )) lc = lua_tocolour( L, 12 ); /* Some sanity checking. */ #if DEBUGGING if (sx >= lt->tex->sx) NLUA_ERROR( L, "Texture '%s' trying to render out of bounds (X position) sprite: %d > %d.", lt->tex->name, sx+1, lt->tex->sx ); if (sx >= lt->tex->sx) NLUA_ERROR( L, "Texture '%s' trying to render out of bounds (Y position) sprite: %d > %d.", lt->tex->name, sy+1, lt->tex->sy ); #endif /* DEBUGGING */ /* Translate as needed. */ t = lt->tex; tx = (tx * t->sw + t->sw * (double)(sx)) / t->rw; tw = tw * t->srw; if (tw < 0) tx -= tw; ty = (ty * t->sh + t->sh * (t->sy - (double)sy-1)) / t->rh; th = th * t->srh; if (th < 0) ty -= th; /* Render. */ gl_blitTexture( t, px, py, pw, ph, tx, ty, tw, th, (lc==NULL) ? NULL : &lc->col ); return 0; }