Advertisement

Allegro RGBA-sprite transparency

Started by October 12, 2004 08:58 AM
3 comments, last by Harry de Man 19 years, 11 months ago
Hey everyone, I'm writing my first game (a tetris-clone), which uses 32-bit RGBA sprites. They all work fine and look really nice, but now I wanted to give them an 'overall transparency-value', similar to using set_trans_blender(r, g, b, alpha) when drawing lines, boxes, etc. etc. (So there are two 'transparency-layers': one incorporated in the RGBA-sprite and one when drawing the entire sprite to the screen). However, this can't be done by using set_trans_blender(0, 0, 0, alpha), because this function call will disbable the previously set _alpha_blender() (used for drawing sprites with alpha-values). So does anyone know if Allegro is even capable of drawing RGBA-sprites with an additional transparency-value, and if so, how?
I think you've got me on that one. Using alpha channels isn't an oft-done thing with Allegro, so that never occured to me. I'm currently asking about it elsewhere, but I think you may have hit a limitation of the library. [sad]

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

Advertisement
Get the example programs and look at exalpha.c.

I think it's basically:

- drawing_mode(DRAW_MODE_TRANS, 0, 0, 0);
- set_alpha_blender();
- draw_trans_sprite(dest, src, x, y);

Edit: Never mind, that wasn't what you asked for. . .

I think you'd need to write your own blender function.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
This seems to work:

#include <allegro.h>unsigned long custom_blender32(unsigned long x,unsigned long y, unsigned long n) {  unsigned long v = (geta32(x)*n)>>8, i = (~v)&0xff;  return makecol32((getr32(x)*v+getr32(y)*i)>>8,                   (getg32(x)*v+getg32(y)*i)>>8,                   (getb32(x)*v+getb32(y)*i)>>8); }int main() {  allegro_init();    set_color_depth(32);  if(set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) != 0)   return 0;    install_keyboard();    BITMAP *sprite = load_bitmap("trans.tga", 0);    if(!sprite)   return 0;    clear_to_color(screen, makecol(128, 200, 255));    set_blender_mode(0, 0, &custom_blender32, 0, 0, 0, 32);  draw_trans_sprite(screen, sprite, 10, 10);    while(!key[KEY_ESC])   {   }    return 0; } END_OF_MAIN();


The last value for set_blender_mode is the alpha value to use (0-255), and replace "trans.tga" with whatever.

Edit: Turns out drawing_mode isn't needed. . .
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
Thanks smart_idiot! I've no idea how it works (I'm quite a newbie), but it does seem to work nicely, and that's all that that matters.

This topic is closed to new replies.

Advertisement