Who can tell me how to show the transparent sprite?
sj971059

The sprite bitmap has a PINK(255,0,255) bg color, and my backbuff is black,
I want that when the sprite is drawn onto the backbuff, his bg color becomes BLACK color. what should I do ? my code doesn't work at all. look:

1#include <allegro.h>
2#include "haphi.h"
3 
4int main(void)
5{
6 BITMAP* backbuff;
7 BITMAP* sprite;
8 DATAFILE* data;
9 allegro_init();
10 install_keyboard();
11 install_timer();
12 set_color_depth(24);
13 set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0);
14 backbuff = create_bitmap(800, 600);
15 clear_to_color(backbuff, makecol(0,0,0));
16 data = load_datafile("haphi.dat");
17 sprite = (BITMAP*)data[WALK_RIGHT].dat;
18 masked_blit(sprite, backbuff, 0, 0, 200, 300, sprite->w, sprite->h);
19 blit(backbuff, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
20 while(!key[KEY_SPACE]);
21 unload_datafile(data);
22 destroy_bitmap(backbuff);
23 return 0;
24}
25END_OF_MAIN()

{"name":"590180","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/b\/4b5f5600e6c03aac9563b9e15118a76a.jpg","w":252,"h":250,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/b\/4b5f5600e6c03aac9563b9e15118a76a"}590180

CursedTyrant

It doesn't work because you saved the image as a JPEG, which compresses colors, and only the magic pink (255, 0, 255) is transparent in allegro... or black in 8 bpp.

At least that's how it looks on the screenshot.

Save the image as either a bmp or a png, and it should work fine.

sj971059

NO, the image in the post is just my screen-save, in my program, the sprite image
is indeed a BMP file stored in a *.dat file.
I use this to get it: BITMAP* sprite = (BITMAP*)data[WALK_RIGHT].dat;
I have used masked_blit(), but it still doesn't work.:-/

Download attachment..my dat resource file in it. thanks.

Inphernic
Quote:

The sprite bitmap has a PINK(255,0,255) bg color

Nope.

CursedTyrant

I don't think I have the grabber atm, but I can see that it's not pure magic pink, because the top of the image is black, and the rest is not. Did you convert the sprite from a jpg or gif, perhaps?

In that case, a solution would be to use MS Paint and paint the background again (preferably using the erase tool).

sj971059

Just Now , I use photoshop7.0 to check the BMP file RGB value and found that some area is (252,2,252) ,some area is (255,0,255), OH, my god......
I got these resource files from internet, after that , I clipped them and added them into a *.dat file, I think I broke their original quality. so that's why the top of the sprite's background color is BLACK, it puzzled me quite a while....

Paul whoknows

Don't use antialiasing.

Thread #587580. Printed from Allegro.cc