tags:

views:

183

answers:

1

I have been building a game in allegro 4.2.1 and need help to remove a specific color to make invisible. The background color is, (255, 0, 255). I have been at the following sites, but they have not helped me much:

http://www.allegro.cc/forums/thread/599210, http://www.cpp-home.com/tutorials/258_1.htm

If someone could provide me with an example, I would be very glad.

A: 

You need to do the following things to enable transparent pixels:

  • Call set_color_depth(32) before calling set_gfx_mode()

  • Load your images after calling set_gfx_mode()

  • Use masked_blit() or draw_sprite() to draw the image.

If you do the above, all "magic pink" pixels (100% red, 0% green, 100% blue) will be treated as transparent.

BITMAP *bmp;
allegro_init();
set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
clear_to_color(screen, makecol(0,0,0));

// once the video mode has been set, it is safe to create/load images.
// this bitmap will be 640x480 with pure pink.
bmp = create_bitmap(640, 480);
clear_to_color(bmp, makecol(255,0,255));
rectfill(bmp, 100,100, 200,200, makecol(255,255,255));

draw_sprite(screen, bmp, 0, 0);

// or
// masked_blit(bmp, screen, 0,0, 0,0, 640,480);
konforce