Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Can I put a translucent pixel?

Credits go to GullRaDriel for helping out!
This thread is locked; no one can reply to it. rss feed Print
Can I put a translucent pixel?
Onewing
Member #6,152
August 2005
avatar

Using the correct drawing_mode, I can use putpixel to put a translucent pixel, but I can't get _putpixel32 to work (it just draws a solid pixel).

Am I going to have to stick with plain old putpixel?

------------
Solo-Games.org | My Tech Blog: The Digital Helm

Mark Oates
Member #1,146
March 2001
avatar

This doesn't directly answer your question, but I recommend trying fblend for your transparent and pattern drawing. The allegro blending functions are very slow.

fblend link

GullRaDriel
Member #3,861
September 2003
avatar

_putpixel32 is directly accessing and setting the bitmap memory data, with no processing at all.

So no working drawing_mode using _putpixel32, just the ole-goud direct putpixel.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Onewing
Member #6,152
August 2005
avatar

That's what I thought. Thanks!

------------
Solo-Games.org | My Tech Blog: The Digital Helm

GullRaDriel
Member #3,861
September 2003
avatar

I think you can compute the final color before _putpixel32'ing it.

I mean something as:

1 
2void trans_putp( BITMAP *bmp , int x , int y , int srccolor ){
3 
4int dstcolor,
5 r1,g1,b1,a
6 r2,g2,b2,
7 r,g,b,
8 _a;
9 
10dstcolor = _getpixel32( bmp , x , y );
11 
12r1=srccolor<<_rgb_r_shift_32;
13g1=srccolor<<_rgb_g_shift_32;
14b1=srccolor<<_rgb_b_shift_32;
15a1=srccolor<<_rgb_a_shift_32;
16r2=dstcolor<<_rgb_r_shift_32;
17g2=dstcolor<<_rgb_g_shift_32;
18b2=dstcolor<<_rgb_b_shift_32;
19a2=dstcolor<<_rgb_a_shift_32;
20 
21_a = ( 255 - a2 );
22 
23r3 = a2 * r2 + _a * r1;
24b3 = a2 * b2 + _a * b1;
25g3 = a2 * g2 + _a * g1;
26 
27a3 = 255 - ( 255 - a1 ) * _a;
28 
29_putpixel32( bmp , x , y , (r3 << _rgb_r_shift_32) |
30 (g3 << _rgb_g_shift_32) |
31 (b3 << _rgb_b_shift_32) |
32 (a3 << _rgb_a_shift_32) );
33 
34}

I think it should be quicker than the putpixel(...) version, with some optimisations of course !

Please make a test ;-)

[edited]

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Go to: