Example #1
0
/**
 * @brief Sets the Lua planet target GFX.
 *
 *    @luaparam tex Texture to set for the planet targetting.
 * @luafunc targetPlanetGFX( tex )
 */
static int guiL_targetPilotGFX( lua_State *L )
{
   LuaTex *lt;
   lt = luaL_checktex( L, 1 );
   gui_targetPilotGFX( lt->tex );
   return 0;
}
Example #2
0
/**
 * @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;
}
Example #3
0
/**
 * @brief Gets the number of sprites in the texture.
 *
 * @usage sprites, sx,sy = t:sprites()
 *
 *    @luaparam t Texture to get sprites of.
 *    @luareturn The total number of sprites followed by the number of X sprites and the number of Y sprites.
 * @luafunc sprites( t )
 */
static int texL_sprites( lua_State *L )
{
   LuaTex *lt;

   /* Get texture. */
   lt = luaL_checktex( L, 1 );

   /* Get sprites. */
   lua_pushnumber( L, lt->tex->sx*lt->tex->sy );
   lua_pushnumber( L, lt->tex->sx );
   lua_pushnumber( L, lt->tex->sy );
   return 3;
}
Example #4
0
/**
 * @brief Frees the texture.
 *
 *    @luaparam t Texture to free.
 * @luafunc __gc( t )
 */
static int texL_close( lua_State *L )
{
   LuaTex *lt;

   /* Get texture. */
   lt = luaL_checktex( L, 1 );

   /* Free texture. */
   gl_freeTexture( lt->tex );
   lt->tex = NULL;

   return 0;
}
Example #5
0
/**
 * @brief Gets the dimensions of the texture.
 *
 * @usage w,h, sw,sh = t:dim()
 *
 *    @luaparam t Texture to get dimensions of.
 *    @luareturn The width and height of the total image followed by the width and height of the sprites.
 * @luafunc dim( t )
 */
static int texL_dim( lua_State *L )
{
   LuaTex *lt;

   /* Get texture. */
   lt = luaL_checktex( L, 1 );

   /* Get all 4 values. */
   lua_pushnumber( L, lt->tex->w  );
   lua_pushnumber( L, lt->tex->h  );
   lua_pushnumber( L, lt->tex->sw );
   lua_pushnumber( L, lt->tex->sh );
   return 4;
}
Example #6
0
/**
 * @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;
}
Example #7
0
/**
 * @brief Renders a texture.
 *
 * This function has variable parameters depending on how you want to render.
 *
 * @usage gfx.renderTex( tex, 0., 0. ) -- Render tex at origin
 * @usage gfx.renderTex( tex, 0., 0., col ) -- Render tex at origin with colour col
 * @usage gfx.renderTex( tex, 0., 0., 4, 3 ) -- Render sprite at position 4,3 (top-left is 1,1)
 * @usage gfx.renderTex( tex, 0., 0., 4, 3, col ) -- Render sprite at position 4,3 (top-left is 1,1) with colour col
 *
 *    @luaparam tex Texture to render.
 *    @luaparam pos_x X position to render texture at.
 *    @luaparam pos_y Y position to render texture at.
 *    @luaparam sprite_x X sprite to render.
 *    @luaparam sprite_y Y sprite to render.
 *    @luaparam colour Colour to use when rendering.
 * @luafunc renderTex( tex, pos_x, pos_y, sprite_x, sprite_y, colour )
 */
static int gfxL_renderTex( lua_State *L )
{
   LuaTex *lt;
   LuaColour *lc;
   double x, y;
   int sx, sy;

   /* Parameters. */
   lc = NULL;
   lt = luaL_checktex( L, 1 );
   x  = luaL_checknumber( L, 2 );
   y  = luaL_checknumber( L, 3 );
   if (lua_isnumber( L, 4 )) {
      sx    = luaL_checkinteger( L, 4 ) - 1;
      sy    = luaL_checkinteger( L, 5 ) - 1;
      if (lua_iscolour(L, 6))
         lc    = luaL_checkcolour(L,6);
   }
   else {
      sx    = 0;
      sy    = 0;
      if (lua_iscolour(L, 4))
         lc    = luaL_checkcolour(L,4);
   }

   /* 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 */

   /* Render. */
   gl_blitStaticSprite( lt->tex, x, y, sx, sy, (lc==NULL) ? NULL : &lc->col );

   return 0;
}
Example #8
0
/**
 * @brief Renders a texture.
 *
 * This function has variable parameters depending on how you want to render.
 *
 * @usage gfx.renderTex( tex, 0., 0. ) -- Render tex at origin
 * @usage gfx.renderTex( tex, 0., 0., col ) -- Render tex at origin with colour col
 * @usage gfx.renderTex( tex, 0., 0., 4, 3 ) -- Render sprite at position 4,3 (top-left is 1,1)
 * @usage gfx.renderTex( tex, 0., 0., 4, 3, col ) -- Render sprite at position 4,3 (top-left is 1,1) with colour col
 *
 *    @luaparam tex Texture to render.
 *    @luaparam pos_x X position to render texture at.
 *    @luaparam pos_y Y position to render texture at.
 *    @luaparam sprite_x X sprite to render.
 *    @luaparam sprite_y Y sprite to render.
 *    @luaparam colour Colour to use when rendering.
 * @luafunc renderTex( tex, pos_x, pos_y, sprite_x, sprite_y, colour )
 */
static int gfxL_renderTex( lua_State *L )
{
    glTexture *tex;
    glColour *col;
    double x, y;
    int sx, sy;

    /* Parameters. */
    col = NULL;
    tex = luaL_checktex( L, 1 );
    x   = luaL_checknumber( L, 2 );
    y   = luaL_checknumber( L, 3 );
    if (lua_isnumber( L, 4 )) {
        sx    = luaL_checkinteger( L, 4 ) - 1;
        sy    = luaL_checkinteger( L, 5 ) - 1;
        if (lua_iscolour(L, 6))
            col = luaL_checkcolour(L,6);
    }
    else {
        sx    = 0;
        sy    = 0;
        if (lua_iscolour(L, 4))
            col = luaL_checkcolour(L,4);
    }

    /* Some sanity checking. */
#if DEBUGGING
    if (sx >= tex->sx)
        NLUA_ERROR( L, "Texture '%s' trying to render out of bounds (X position) sprite: %d > %d.",
                    tex->name, sx+1, tex->sx );
    if (sx >= tex->sx)
        NLUA_ERROR( L, "Texture '%s' trying to render out of bounds (Y position) sprite: %d > %d.",
                    tex->name, sy+1, tex->sy );
#endif /* DEBUGGING */

    /* Render. */
    gl_blitStaticSprite( tex, x, y, sx, sy, col );

    return 0;
}
Example #9
0
/**
 * @brief Gets the sprite that corresponds to a direction.
 *
 * @usage sx, sy = t:spriteFromdir( math.pi )
 *
 *    @luaparam t Texture to get sprite of.
 *    @luaparam a Direction to have sprite facing (in radians).
 *    @luareturn x and y positions of the sprite.
 * @luafunc spriteFromDir( t, a )
 */
static int texL_spriteFromDir( lua_State *L )
{
   double a;
   LuaTex *lt;
   int sx, sy;

   /* Params. */
   lt = luaL_checktex( L, 1 );
   a  = luaL_checknumber( L, 2 );

   /* Calculate with parameter sanity.. */
   if ((a >= 2.*M_PI) || (a < 0.)) {
      a = fmod( a, 2.*M_PI );
      if (a < 0.)
         a += 2.*M_PI;
   }
   gl_getSpriteFromDir( &sx, &sy, lt->tex, a );

   /* Return. */
   lua_pushinteger( L, sx+1 );
   lua_pushinteger( L, sy+1 );
   return 2;
}
Example #10
0
/**
 * @brief Sets the Lua planet target GFX.
 *
 *    @luatparam Tex tex Texture to set for the planet targeting.
 * @luafunc targetPlanetGFX( tex )
 */
static int guiL_targetPilotGFX( lua_State *L )
{
   gui_targetPilotGFX( luaL_checktex( L, 1 ) );
   return 0;
}