- Online Community Forums » Programming Questions » Pink is not Transparent with Grabber and Bitmaps

This thread is locked; no one can reply to it. rss feed Print
Pink is not Transparent with Grabber and Bitmaps
Justin Slowik
Member #7,235
May 2006

Hey all, I used to be pretty good with Allegro, but this was about 4 or 5 years ago. A few days ago I decided to get back into it, but I'm having some issues. Basically what I'm tryin to do right now is display a basic tiled map and my character. However, when I display the character to be on top of the map, transparency does not work, and the pink surrounding box is still there. here's some code:

This is my main function where things are initialized and the character is loaded (it'll be broken down into more functions at a later time):

1int main(int argc, int *argv[])
3 allegro_init();
4 install_keyboard();
5 set_color_depth(24);
6 if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0) != 0) //Defaulted to 800x600, may make scalable later
7 abort_on_error("Couldn't set graphic mode!");
9 BITMAP *bmp = create_bitmap(800,600); //main screen
10 DATAFILE *character_data = load_datafile("PCs.dat");
11 BITMAP *character_buffer;
12 string versionNumber = "v0.01-alpha1";
13 clear_bitmap(bmp);
14 if (!character_data) {
15 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
16 allegro_message("Error loading Character Datafile");
17 return 1;
18 }
20 acquire_screen();
21 draw_map();
22 character_buffer = create_bitmap(32,32);
23 clear_bitmap(character_buffer);
24 //draw_sprite(bmp, (BITMAP *)character_data[0].dat, 0, 0);
25 /* Blit to screen */
27 blit((BITMAP *)character_data[0].dat, screen, 0, 0,0,0,32,32);
29 int size = text_length(font, versionNumber.c_str()); //display version number
30 textout_right_ex(screen, font, versionNumber.c_str(), SCREEN_W-10, SCREEN_H-10, makecol(255,255,255), -1);
31 release_screen();
32 /* wait for a keypress */
33 readkey();
34 return 0;

and here's the code for loading the map:

1void draw_map()
3 BITMAP *land = create_bitmap(32,32);
4 DATAFILE *landFile;
5 landFile = load_datafile("map.dat");
6 clear_bitmap(land);
7 if (!landFile) {
8 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
9 allegro_message("Error loading Map\n");
10 return;
11 }
12 int mapXtotal = 20 * 32;
13 int mapYtotal = 18 * 32;
14 for (int x = 0; x < mapXtotal; x = x+32){
15 for (int y = 0; y <= mapYtotal; y = y+32){
16 draw_sprite(land,(BITMAP *)landFile[0].dat,x,y);
17 blit(land,screen,0,0,x,y,32,32);
18 }
19 }

I've double checked grabber, and all images are listed being 24 bit, and according to photoshop the pink is (255,0,255). So does anyone know why the program displays this still:


any help would be greatly appreciated!

Matthew Leverton
Supreme Loser
January 1999


blit((BITMAP *)character_data[0].dat, screen, 0, 0,0,0,32,32);

Is this the line that is drawing the guy? It needs to be a masked blit or draw sprite.

Justin Slowik
Member #7,235
May 2006

i originally had that, but i had some variables wrong. Now im getting closer, but instead of displaying Pink now, it displays black!

this is what i changed that snippet to:

        character_buffer = create_bitmap(32,32);
  draw_sprite(character_buffer, (BITMAP *)character_data[0].dat, 0, 0);
  /* Blit to screen */

  blit(character_buffer, screen, 0, 0,0,0,32,32);

any idea why all the pink area is black now? am I deleting that tile somehow?

Member #4,355
February 2004

I think clear_bitmap is making the background of the character_buffer black... try clear_to_color(character_buffer, makecol(255, 0, 255)) and draw_sprite'ing that to the screen. I suggest just having one buffer instead of a buffer for the character only though...

EDIT: Code:

character_buffer = create_bitmap(32,32);
clear_to_color(character_buffer, makecol(255, 0, 255));
draw_sprite(character_buffer, (BITMAP *)character_data[0].dat, 0, 0);
/* Blit to screen */

draw_sprite(screen, character_buffer, 0, 0);

EDIT2: Or, for your case, why not just draw_sprite directly to the screen..? Why're you using a buffer for the character?

Justin Slowik
Member #7,235
May 2006

Thanks Mokkan! You're fix worked. I changed my code to

  draw_sprite(screen,(BITMAP *)character_data[0].dat,0,0);

and it worked perfectly!

Member #2,981
December 2002

What is so special about draw_sprite over masked_blit? I've always wondered that myself.

Matthew Leverton
Supreme Loser
January 1999

2.0 changelog said:

There is no longer such a thing as a SPRITE structure. The sprite drawing code now draws bitmaps onto other bitmaps, which is a much more flexible way of doing things. The datafile reader will convert all your old sprites to bitmaps as it loads them in, so the only practical difference this is likely to make is that the sprite drawing routines can't draw opaque sprites any more (but you can use a blit instead).

Member #794
November 2000


What is so special about draw_sprite over masked_blit?

Less variables to pass that you don't normally care about (the values I typically pass to masked_blit() are those that make it behave the same as draw_sprite()) and being able to do 8bit->any depth blits (masked_blit() cannot do colour conversions at all).

Go to: