Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » translucent putpixel

This thread is locked; no one can reply to it. rss feed Print
translucent putpixel
William Labbett
Member #4,486
March 2004
avatar

hi,
i've got a 32 bit bitmap (lucky me) and I need to draw black pixels on it at varying degrees of translucency. i've tried this

_putpixel32(bmp, x, y, makeacol32(0, 0, 0, 128));

but this draws solid black pixels. Can someone help please ?

Also, I was wondering why functions like putpixel always have an int arg for the colour when they don't use a palette in non 8 bit modes.

bhagabhi
Member #1,660
November 2001

William Labbett said:

i've got a 32 bit bitmap (lucky me) and I need to draw black pixels on it at varying degrees of translucency. i've tried this

_putpixel32(bmp, x, y, makeacol32(0, 0, 0, 128));

but this draws solid black pixels. Can someone help please ?

Check out translucent drawing in the manual.

some code like this should do the trick:

drawing_mode(DRAW_MODE_TRANS,NULL,0,0);
// the 128 on the following line is the translucency: 0 totally translucent, 255 fully black
set_trans_blender(0,0,0,128);
putpixel(target,x,y,makecol(0,0,0));
solid_mode();

... and of course, you shouldn't do this pixel by pixel - draw all translucent stuff before going back to "normal" mode with "solid_mode()" - or use rectfill, draw_trans_sprite or similar.

regarding your other question - its using an int because that is enough - you'll have enough room to store the data that is necessary - 8 bits for all the r,g and b, and also 8 bits for alpha channel. The authors of allegro could have made a struct or something similar of it though, but I think ints are used for simplicity (speed also might be a part of it.)

To get (for example) the red channel out of a pixel (an int) use the get_r / get_g / get_b functions. More in here: (Truecolor pixel formats)

William Labbett
Member #4,486
March 2004
avatar

thanks for the reply. i've only got internet away from home at the moment so i'm late replying. I'll try the code.
Another question :- how is makeacol32() used ?

bhagabhi
Member #1,660
November 2001

I am not an expert on the alpha-drawing stuff - but my guess is that you make a 32-bit bitmap using create_bitmap_ex(32,width,height) - and then you can draw to it with putpixel (or other primitive drawing stuff) in combination with makeacol (to make regions of the bitmap somewhat translucent) , and then using draw_trans_sprite to draw the sprite(bitmap) to the screen/other bitmap.

(sorry for not linking the commands to the manual - I am sure you can find what you are after anyhow - in the online manual or the one that comes with the allegro package).

There should be people here that knows more about it than me though.

[edit]
Found some minor problems with the commenting on this page though:

http://www.allegro.cc/manual/api/bitmap-objects/create_bitmap_ex

Looks like the same problem is in the manual in the allegro package too.
(reported to AD.)

[edit2] oops, no, I didn't mail - having problems mailing to alleg-devel... hope someone in charge sees this then.[/edit2]

[/edit]

Dustin Dettmer
Member #3,935
October 2003
avatar

Allegro translucency support is severely lacking. Support for it has pretty much stopped in favor of hardware accelerated libraries like OpenGL or Direct3D.

If you're looking for something actually useful with translucency, you're looking in the wrong place.

Go to: