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?
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.
_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.
That's what I thought. Thanks!
I think you can compute the final color before _putpixel32'ing it.
I mean something as:
1 | |
2 | void trans_putp( BITMAP *bmp , int x , int y , int srccolor ){ |
3 | |
4 | int dstcolor, |
5 | r1,g1,b1,a |
6 | r2,g2,b2, |
7 | r,g,b, |
8 | _a; |
9 | |
10 | dstcolor = _getpixel32( bmp , x , y ); |
11 | |
12 | r1=srccolor<<_rgb_r_shift_32; |
13 | g1=srccolor<<_rgb_g_shift_32; |
14 | b1=srccolor<<_rgb_b_shift_32; |
15 | a1=srccolor<<_rgb_a_shift_32; |
16 | r2=dstcolor<<_rgb_r_shift_32; |
17 | g2=dstcolor<<_rgb_g_shift_32; |
18 | b2=dstcolor<<_rgb_b_shift_32; |
19 | a2=dstcolor<<_rgb_a_shift_32; |
20 | |
21 | _a = ( 255 - a2 ); |
22 | |
23 | r3 = a2 * r2 + _a * r1; |
24 | b3 = a2 * b2 + _a * b1; |
25 | g3 = a2 * g2 + _a * g1; |
26 | |
27 | a3 = 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]