Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » [A5.1] Blending bug

This thread is locked; no one can reply to it. rss feed Print
[A5.1] Blending bug
weapon_S
Member #7,859
October 2006
avatar

On Linux, Debian Squeeze.
While it does the same thing for all blending modes (clear bitmap, set new blender, draw rectangles), the cases in which a subtractive blender was set yield a bitmap all white, no alpha. I used al_set_separate blender, but only because al_set_blender gave me (the same) erroneous results. (I was initially trying to test something else...)

blend_fail.cpp#SelectExpand
1#include <string> 2#include <algorithm> 3#include <allegro5/allegro5.h> 4#include <allegro5/allegro_primitives.h> 5#include <allegro5/allegro_native_dialog.h> 6#include <allegro5/allegro_image.h> 7 8using namespace std; 9 10const int BMP_WIDTH = 512; 11const int BMP_HEIGHT = 256; 12 13void fail(const char*); 14void clear_screen(); 15void test_all(const char*); 16 17int main(){ 18 ALLEGRO_DISPLAY* dis; 19 20 //Initialization 21 if (al_init()&&al_init_primitives_addon()&&al_init_image_addon()) 22 { 23 dis = al_create_display(BMP_WIDTH * 2 + 3, BMP_HEIGHT + 2); 24 } 25 else{ 26 fail("Cannot initialize."); 27 return 1; 28 } 29 30 if(! dis){ 31 fail("Cannot create display."); 32 return 1; 33 } 34 35 al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO, ALLEGRO_ADD, ALLEGRO_ZERO, ALLEGRO_ONE); 36 test_all("Overwrite"); 37 38 al_set_separate_blender(ALLEGRO_DEST_MINUS_SRC, ALLEGRO_ALPHA, ALLEGRO_ONE, ALLEGRO_ADD, ALLEGRO_ZERO, ALLEGRO_ONE); 39 test_all("Alpha-scaled subtraction"); 40 41 al_set_separate_blender(ALLEGRO_DEST_MINUS_SRC, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, ALLEGRO_ADD, ALLEGRO_ZERO, ALLEGRO_ONE); 42 test_all("Alpha-correct subtraction"); 43 44 al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_ONE, ALLEGRO_ADD, ALLEGRO_ZERO, ALLEGRO_ONE); 45 test_all("Alpha-scaled addition"); 46 47 al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, ALLEGRO_ADD, ALLEGRO_ZERO, ALLEGRO_ONE); 48 test_all("Alpha-correct addition"); 49 50 return 0; 51} 52 53void fail(const char* why){ 54 al_show_native_message_box(0, "FAIL", why, why, 0, ALLEGRO_MESSAGEBOX_ERROR); 55 return; 56} 57 58void clear_screen(){ 59 int prev_blender[6]; 60 al_get_separate_blender(prev_blender, prev_blender + 1, prev_blender + 2, prev_blender + 3, prev_blender + 4, prev_blender + 5); 61 al_clear_to_color(al_map_rgb(255,0,255)); 62 al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO, ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); 63 al_draw_filled_rectangle( 64 1.5f, 65 1.5f, 66 BMP_WIDTH + 1.5f, 67 BMP_HEIGHT + 1.5, 68 al_map_rgba(255,255,255, 255) 69 ); 70 al_draw_filled_rectangle( 71 BMP_WIDTH + 2.5f, 72 1.5f, 73 2.0f * BMP_WIDTH + 2.5f, 74 BMP_HEIGHT + 1.5f, 75 al_map_rgba( 0, 0, 0, 255) 76 ); 77 al_set_separate_blender(prev_blender[0], prev_blender[1], prev_blender[2], prev_blender[3], prev_blender[4], prev_blender[5]); 78 return; 79} 80 81void test_all(const char* what){ 82 ALLEGRO_BITMAP* buffer = al_create_bitmap(BMP_WIDTH*2 + 3, BMP_HEIGHT + 2); 83 string name(what); 84 name.erase(remove_if(name.begin(), name.end(), ::isspace), name.end()); 85 86 al_set_target_bitmap(buffer); 87 clear_screen(); 88 al_save_bitmap( (name + "fail.png").c_str(), buffer); 89 al_destroy_bitmap(buffer); 90 return; 91}

Without creating a display it gives correct results.

I updated using SVN (but I'm not sure I purged correctly...). Allegro reports version 5.1.1.0.

Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-8' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-targets=all --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.4.5 (Debian 4.4.5-8)

Compiled using:

g++ ./blend_fail.cpp -oblend_failnix2 -lallegro-debug -lallegro_primitives-debug -lallegro_image-debug -lallegro_dialog-debug

Logs, sources and (some) output attached. (Logs are from different respective programs.)

Elias
Member #358
May 2000

I compiled and executed blend_fail.cpp and it wrote 5 .png files. They look all identical except OverWritefail.png which has no black bar to the left.

Do you get something else? (It seems for you Alpha-correctsubtractionfail.png is all white?) Is that the only difference?

Also, which driver are you using?

Do all of Allegro's unit tests succeed? (cd build; cd tests; ./test_driver ../../tests/*.ini)

--
"Either help out or stop whining" - Evert

weapon_S
Member #7,859
October 2006
avatar

All tests work.
On linux: the two subtractive ones give me an all-white image. The others give me white (L) and black (R). They should all output the latter.
On windows: they all output the latter.
But I'm getting a somewhat similar bug under Windows, in the lines of:
WTH works on Windows now... Linux giving me inconsistent results upon recompilation...
[append]
I think part of the problem is, files I forgot to delete don't get replaced and the subtractive blending can fail silently (if driver doesn't support it?)

Go to: