コード例 #1
0
ファイル: nlua_gfx.c プロジェクト: Elderman/naev
/**
 * @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;
}
コード例 #2
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;
}