Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Drawing to bitmap

This thread is locked; no one can reply to it. rss feed Print
Drawing to bitmap
kyborg
Member #15,328
October 2013

Hello,
consider following code

#SelectExpand
1int main(void) 2{ 3 al_init(); 4 al_init_image_addon(); 5 6 ALLEGRO_DISPLAY* display = al_create_display(800, 600); 7 8 al_clear_to_color(al_map_rgb(0, 0, 0)); 9 10 al_flip_display(); 11 12 ALLEGRO_BITMAP* bitmap = al_create_bitmap(160, 80); 13 14 al_set_target_bitmap(bitmap); 15 16 al_clear_to_color(al_map_rgb(0, 100, 0)); 17 18 19 al_save_bitmap("green.png", bitmap); //green.png is green 20 al_flip_display(); //display is now green 21 cin.get(); 22 23 al_set_target_backbuffer(display); 24 25 al_clear_to_color(al_map_rgb(100, 0, 0)); 26 27 al_save_bitmap("red.png", bitmap); //red.png is red 28 al_flip_display(); //display is now red 29 cin.get(); 30 31 return 0; 32}

I read documentation and I thought that display should never be green, because I am drawing green to bitmap and bitmap "red.png" should be green. But it is not.
If it is behaving correctly, please tell me how to draw only to bitmap and only to display.
Allegro version is 5.1.8 and OS is Debian.
Also please tell me how is this program behaving on your computer.
Thanks

Arthur Kalliokoski
Second in Command
February 2005
avatar

It didn't save the bitmaps for me at all until I put a al_init_image_addon() right after al_init(). Oh, yeah, there is no "init_allegro()" unless you didn't post a function you wrote yourself, but you must have or it wouldn't have compiled. I used "al_init()".

Anyway, it now shows a blank screen, which turns to red, and both bitmap files are green.

They all watch too much MSNBC... they get ideas.

kyborg
Member #15,328
October 2013

Thanks for reply. Yes init_allegro() is function I wrote myself. It only calls al_init() and al_init_image_addon(). I will change code in the first post because this function can be confusing.
So it behave differently on your computer. What Allegro version are you using?
Can it be caused be operating system? Because I have unstable version of it...
Also I have tried some Allegro tests and some of them failed. For example "test_backbuffer.ini" in allegro/tests has 4 failed tests.
Maybe some moderator can move this to Allegro Development section, because it looks like bug.

Arthur Kalliokoski
Second in Command
February 2005
avatar

I'm using Allegro 5.1.7 with Linux, Nvidia GeForce GTX 650.

They all watch too much MSNBC... they get ideas.

kyborg
Member #15,328
October 2013

Did you try the tests? Did some of them failed?

Arthur Kalliokoski
Second in Command
February 2005
avatar

What tests? The Allegro examples? They all worked, except the ones for hardware I don't have (such as dual monitors). There was also some resizing thing that didn't work right a couple of years ago, I don't think it's fixed yet.

I don't think I tried them all because it's so tedious, there were a couple of GLSL examples I just ran a few days ago and I'm pretty sure I'd never seen them before (they worked correctly too).

[EDIT]
I always get rid of the noveau (?) open source driver and install the Nvidia proprietary driver because the noveau driver sucks so hard, for example, the ex_gldepth example doesn't work right with it. OTOH, about a year ago I reported a problem and spent about three days trying to fix it when I saw a new Nvidia driver had come out and it worked correctly then. Shit happens.

They all watch too much MSNBC... they get ideas.

kyborg
Member #15,328
October 2013

No. When you download allegro, there is directory "tests". In this directory there is source file "test_driver.c" and few other files for example "test_bitmaps.ini", "test_backbuffer.ini".

Arthur Kalliokoski
Second in Command
February 2005
avatar

I didn't try those, I just fiddled with it for two minutes and tried about five of them (including test_bitmap.ini) and they all flashed a window too fast to really see what's happening and the console is full of OK messages.

They all watch too much MSNBC... they get ideas.

kyborg
Member #15,328
October 2013

Would you please try test_backbuffer.ini? I have this output from it:

OK test bbsrc [sw]
FAIL test bbsrc [hw] - RMS error is 35.2781
hash_hw=0c801dc5
sig_hw=ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
OK test bbsrc translate [sw]
FAIL test bbsrc translate [hw] - RMS error is 33.9109
hash_hw=0c801dc5
sig_hw=ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
OK test bbsrc outside [sw]
FAIL test bbsrc outside [hw] - RMS error is 27.0248
hash_hw=0c801dc5
sig_hw=ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
OK test bbsrc tint [sw]
FAIL test bbsrc tint [hw] - RMS error is 27.2208
hash_hw=0c801dc5
sig_hw=ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg

total tests: 8
passed tests: 4
failed tests: 4

But I dont know, what does it mean... Maybe it is connected to the original error I had.

Arthur Kalliokoski
Second in Command
February 2005
avatar

pepsi@fractal:/home/prog/allegro-5.1.7/build/tests 05:45 AM $ test_driver ../../tests/test_backbuffer.ini 
OK   test bbsrc [sw]
OK   test bbsrc [hw]
OK   test bbsrc translate [sw]
OK   test bbsrc translate [hw]
OK   test bbsrc outside [sw]
OK   test bbsrc outside [hw]
OK   test bbsrc tint [sw]
OK   test bbsrc tint [hw]

total tests:  8
passed tests: 8
failed tests: 0

They all watch too much MSNBC... they get ideas.

pkrcel
Member #14,001
February 2012

Kyborg those tests seems related to hardware problems, of some sort.

I'm not able to be more helpful thou :(

It is unlikely that Google shares your distaste for capitalism. - Derezo
If one had the eternity of time, one would do things later. - Johan Halmén

Arthur Kalliokoski
Second in Command
February 2005
avatar

Kyborg, what video card and driver do you have?

If it's Nvidia I'm using NVIDIA-Linux-x86_64-331.20.run installer for 64 bit linux.

They all watch too much MSNBC... they get ideas.

kyborg
Member #15,328
October 2013

My video card is AMD Radeon HD 7570M. I dont know which driver I am using.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

This part of the code is fine :

The next part flips the display without drawing anything to it (which means it could display anything) (you never set the drawing target back to the backbuffer) :

 ALLEGRO_BITMAP* bitmap = al_create_bitmap(160, 80);
 al_set_target_bitmap(bitmap);
 al_clear_to_color(al_map_rgb(0, 100, 0));
 al_save_bitmap("green.png", bitmap); //green.png is green
 al_flip_display(); //display could hold anything
 cin.get();

green.png should now exist and be green.

The last part of the code you showed us should save red.png as a green bitmap as well, because the green bitmap is the bitmap you specified to save :

 al_set_target_backbuffer(display);
 al_clear_to_color(al_map_rgb(100, 0, 0));
 al_save_bitmap("red.png", bitmap); //red.png is green b/c bitmap is green
 al_flip_display(); //display is now red
 cin.get(); return 0; }

The screen should be red now.

Go to: