SOLVED Allegro: trying to draw a 32 bit RGBA bitmap to the screen

Started by
8 comments, last by darenking 18 years, 8 months ago
This is a very murky business indeed. I set up my graphics like this: set_color_depth(32); set_gfx_mode(GFX_AUTODETECT_WINDOWED, width, height, 0, 0); ...and I create my screen buffer like this: BITMAP* buffer; I can load in 24 bit bitmaps and draw them to the screen easy enough: BITMAP* sprite = load_bitmap("data/robot.bmp", NULL); draw_sprite(buffer, sprite, 0, 0); But I also need to be able to draw 32 bit RGBA bitmaps to the screen, with the alpha blending effectively smoothing the edges, like anti-aliasing on a font. I've tried it like this: BITMAP* sprite2 = load_bitmap("data/monster.bmp", NULL); drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); set_write_alpha_blender(); //also tried set_alpha_blender() draw_trans_sprite(buffer, sprite2, 0, 0); Here's a link to my sprite, perhaps I have set up the alpha layers wrong? If you load it into Photoshop or whatever, I think you will find it is correct. http://www.server32.net/monster.zip Any help appreciated. [Edited by - darenking on August 14, 2005 2:07:32 PM]
Advertisement
Maybe i'm wrong, but can .bmp really store Alpha channels?
Good point. I need to export the files as .tga instead of .bmp.

OK, I've got that working.

Can someone tell me if I have to do anything to un-set the alpha blender? In other words, every loop I have set_alpha_blender() before I draw the trans sprites. Do I need to put anything after I've drawn the trans sprites to go back to a normal drawing mode? Do I have to set_alpha_blender every loop?
As long as you're not explicitly changing the drawing mode, you should only have to set up the alpha blender once; you don't have to call the alpha blender every loop. In this case, using drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0) and set_alpha_blender() at the start of your program, should do the job.

However, if you want to use the default mode for drawing, you'll have to use solid_mode(), which is a shorter version for drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0).
Will the program run more slowly if I leave it in trans mode all the time? I mean assuming that lots of my images have no alpha layer.
I'm not sure what you mean by trans mode: do you mean the alpha blending mode (used for blitting sprites with alpha layers), or the trans blender (which is used for drawing primitives and blitting sprites w/o alpha layers, with a certain transparency value)?

Anyway, in the latter case, drawing primitives and blitting ordinary sprites will be slower of course, as the transparency value must be taken into account when drawing/blitting.
In the first case (alpha blending) the method of blitting ordinary sprites (using draw_sprite) and drawing primitives is not affected, so this won't have an impact on your game performance.

I hope this is clear, but just remember that as long as you're only using the alpha blender you shouldn't experience a major decrease in perfomance when blitting ordinary sprites.

On a side note, if you're using a lot of RGBA-sprites you might want to take a look at Fblend, which is a library for Allegro to handle alpha blending much faster.
Fblend sounds interesting, but it's only Beta and it looks like they haven't worked on it since 2002. Won't it be buggy? Have you used it?
No, it's not buggy. And it's definitely faster than the Allegro blending functions. [smile]

Jesus saves ... the rest of you take 2d4 fire damage.

Is it difficult to use? Presumably I have to install the libraries or something. I've only ever used the libraries (if that is the correct terminology) that come with Allegro.

This topic is closed to new replies.

Advertisement