Jump to content
  • Advertisement
Sign in to follow this  
Harry de Man

Allegro RGBA-sprite transparency

This topic is 5394 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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. . .

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!