[AD] New function (blit_gouraud)

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


I have written a trivial "blit_gouraud" that draws like blit() but
provides for lighting the corners.  It works in all graphics modes, can
draw on any surface and doesn't require floating point stuff so it's
rather portable.

It's attached.  I hope this is the right list for this sort of thing.

It's a good function to compliment draw_gouraud_sprite()...

Tom

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/
/* Gouraud blitting routines */
#include <allegro.h>

/* c1 ---- c2
 *  |      |
 * c3 ---- c4
 */
void blit_gouraud(BITMAP *src, BITMAP *dest, int src_x, int src_y,
                  int dest_x, int dest_y, int width, int height,
                  int c1, int c2, int c3, int c4)
{
    int dep1, dep2, x, y, d1, d2, dx, C, C1, C2;
    unsigned long c, r, g, b, temp;

    dep1 = bitmap_color_depth(src);
    dep2 = bitmap_color_depth(dest);
    /* find deltas */
    d1 = ((c3 - c1) << 16) / height;
    d2 = ((c4 - c2) << 16) / height;
    C1 = c1<<16;
    C2 = c2<<16;
    for (y = 0; y < height; y++) {
        /* find scanline points */
        C = C1;
        dx = (C2 - C1) / width;
        for (x = 0; x < width; x++) {
            /* calc the new shade value as we go across */
            C += dx;
            temp = C>>16;
            /* get pixel and shade it */
            c = getpixel(src, src_x+x, src_y+y);
            r = (getr_depth(dep1, c) * temp) >> 8;
            g = (getg_depth(dep1, c) * temp) >> 8;
            b = (getb_depth(dep1, c) * temp) >> 8;
            putpixel(dest, dest_x+x, dest_y+y, makecol_depth(dep2, r, g, b));
        }
        C1 += d1;
        C2 += d2;
    }
}

/*dummy example */
int main(void)
{
    BITMAP *bmp;
    int c[4], x;

    allegro_init();
    install_timer();
    set_color_depth(24);
    set_gfx_mode(GFX_SAFE, 320, 240, 0, 0);
    bmp = load_bitmap("test.bmp", NULL);

    while (!keypressed())
        for (x = 0; x < 4; x++)
            c[x] = rand()&255;
        vsync();
        blit_gouraud(bmp, screen, 0, 0, 0, 0, 64, 64, c[0], c[1], c[2], c[3]);
        rest(500);
    }
    return 0;
}
        


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/