Fade In/Out com fblend no Allegro

Acho que muita gente já deve ter usado aquele famoso código de fade in/out que tem no site da Allegro.cc, certo? Eu mesmo uso ele bastante! Mas como todo mundo também já deve saber, as rotinas de blend da Allegro são lentas, por isso existe a biblioteca addon fblend, que é bem mais rápida.

Se você estiver utilizando ela no seu projeto e desejar usar fade in/out, você pode utilizar estas funções aqui:

void fade_in(BITMAP *bmp_orig, int speed)
{
   BITMAP *bmp_buff;

    if ((bmp_buff = create_bitmap(SCREEN_W, SCREEN_H)))
    {
        int a;
        if (speed <= 0) speed = 16;

        for (a = 0; a < 256; a+=speed)
        {
            clear(bmp_buff);
            fblend_trans(bmp_orig, bmp_buff, 0, 0, a);
            blit(bmp_buff, screen, 0,0, 0,0, SCREEN_W, SCREEN_H);
        }
        destroy_bitmap(bmp_buff);
    }

    blit(bmp_orig, screen, 0,0, 0,0, SCREEN_W, SCREEN_H);
}

void fade_out(int speed)
{
    BITMAP *bmp_orig, *bmp_buff;

    if ((bmp_orig = create_bitmap(SCREEN_W, SCREEN_H)))
    {
        if ((bmp_buff = create_bitmap(SCREEN_W, SCREEN_H)))
        {
            int a;
            blit(screen, bmp_orig, 0,0, 0,0, SCREEN_W, SCREEN_H);
            if (speed <= 0) speed = 16;

            for (a = 255-speed; a > 0; a-=speed)
            {
                clear(bmp_buff);
                fblend_trans(bmp_orig, bmp_buff, 0, 0, a);
                blit(bmp_buff, screen, 0,0, 0,0, SCREEN_W, SCREEN_H);
            }
            destroy_bitmap(bmp_buff);
        }
        destroy_bitmap(bmp_orig);
    }

    rectfill(screen, 0,0, SCREEN_W,SCREEN_H, makecol(0,0,0));
}

Que nada mais são do que aquelas funções que tem no site da A.cc, só que com o fblend, não com o blend do Allegro.

Se você não sabe o que é a fblend, aguarde mais um pouco que logo eu pretendo fazer um tutorialzinho básico de como instalá-la e usá-la! =D

Bom uso!

Google Buzz
Compartilhar: Share this post with the world.
  • Twitter
  • Posterous
  • Facebook
  • del.icio.us
  • Digg
  • Friendfeed
  • Google
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Technorati

Posts semelhantes:

  1. Fade In/Out com Allegro
  2. Entrada de Texto no Allegro
  3. MotionBlur com Allegro
  4. Algumas Implementações de Primitivas com Allegro
  5. Fontes TTF no Allegro

One comment

  • Pingback: Fade In/Out com Allegro « CrociDBlog

  • Leave a Reply

    Your email address will not be published. Required fields are marked *

    *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>