Icon on Mac
ortica

Hi guys, I have a problem with the icon. I usually use a mac, now with Catalina beta, and if I use these instructions:

#SelectExpand
1 icon = al_load_bitmap("../assets/img/ico.png"); 2 al_convert_mask_to_alpha(icon, al_map_rgb(0, 255, 0)); 3 al_set_display_icon(display, icon);

the screen goes black, the icon is loaded, and the game works (I entered some cout and I see that the game below continues to run).
The nice thing is that if I run the same code in a virtual machine with ubuntu 19.04 everything works perfectly, both the icon and the drawing on the screen.
How can I deal with this apparent incompatibility problem between Allegro and MacOS? ???
(It has nothing to do with the fact that mac os is in beta because it has always done so)

Peter Hull

I tried the Allegro example program ex_icon and it worked OK (on Mojave) - maybe look at the source for that and see if there's some difference between the way it does it and the way you're doing it?
https://github.com/liballeg/allegro5/blob/master/examples/ex_icon.c

ortica

The examples work in the sense that they load the icon. But they don't have anything drawn on the screen, so I can't test them as they are. I modified the ex_icon.c file in this way

#SelectExpand
1#include <allegro5/allegro.h> 2#include "allegro5/allegro_image.h" 3 4#include "common.c" 5 6int main(int argc, char **argv) 7{ 8 ALLEGRO_DISPLAY *display; 9 ALLEGRO_BITMAP *icon1; 10 ALLEGRO_BITMAP *icon2; 11 // add this line 12 ALLEGRO_BITMAP *img; 13 ALLEGRO_EVENT_QUEUE *queue; 14 ALLEGRO_TIMER *timer; 15 int i; 16 17 (void)argc; 18 (void)argv; 19 20 if (!al_init()) { 21 abort_example("Could not init Allegro.\n"); 22 } 23 al_install_keyboard(); 24 al_init_image_addon(); 25 init_platform_specific(); 26 27 display = al_create_display(320, 200); 28 if (!display) { 29 abort_example("Error creating display\n"); 30 } 31 al_clear_to_color(al_map_rgb_f(0, 0, 0)); 32 al_flip_display(); 33 // add this line 34 img = al_load_bitmap("data/alexlogo.bmp"); 35 /* First icon: Read from file. */ 36 icon1 = al_load_bitmap("data/icon.tga"); 37 if (!icon1) { 38 abort_example("icon.tga not found\n"); 39 } 40 41 /* Second icon: Create it. */ 42 al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP); 43 icon2 = al_create_bitmap(16, 16); 44 al_set_target_bitmap(icon2); 45 for (i = 0; i < 256; i++) { 46 int u = i % 16; 47 int v = i / 16; 48 al_put_pixel(u, v, al_map_rgb_f(u / 15.0, v / 15.0, 1)); 49 } 50 al_set_target_backbuffer(display); 51 52 al_set_window_title(display, "Changing icon example"); 53 54 timer = al_create_timer(0.5); 55 queue = al_create_event_queue(); 56 al_register_event_source(queue, al_get_keyboard_event_source()); 57 al_register_event_source(queue, al_get_display_event_source(display)); 58 al_register_event_source(queue, al_get_timer_event_source(timer)); 59 al_start_timer(timer); 60 61 for (;;) { 62 ALLEGRO_EVENT event; 63 al_wait_for_event(queue, &event); 64 65 if (event.type == ALLEGRO_EVENT_KEY_DOWN && 66 event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { 67 break; 68 } 69 if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { 70 break; 71 } 72 if (event.type == ALLEGRO_EVENT_TIMER) { 73 // add this line 74 al_draw_bitmap(img, 0, 0, 0); 75 al_set_display_icon(display, (event.timer.count & 1) ? icon2 : icon1); 76 // add this line 77 al_flip_display(); 78 } 79 } 80 81 al_uninstall_system(); 82 83 return 0; 84}

and behaves the same way.

Peter Hull

That is odd because your code worked OK for me.
Using allegro 5.2.5[1]
Are you saying it never worked, even on previous versions of MacOS?

Thread #617898. Printed from Allegro.cc