|
Drawing to bitmap |
kyborg
Member #15,328
October 2013
|
Hello, 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. |
Arthur Kalliokoski
Second in Command
February 2005
|
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. |
Arthur Kalliokoski
Second in Command
February 2005
|
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
|
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] 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
|
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] total tests: 8 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
|
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 |
Arthur Kalliokoski
Second in Command
February 2005
|
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
|
This part of the code is fine : int main(void) { al_init(); al_init_image_addon(); ALLEGRO_DISPLAY* display = al_create_display(800, 600); al_clear_to_color(al_map_rgb(0, 0, 0)); al_flip_display(); 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. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|