al_create_mouse_cursor returns null
hyreia77

I'm curious what I'm doing wrong. What do I need to do for al_create_mouse_cursor to work? I'm using the pre-compiled MSVC2010 binaries on Windows 7.

#SelectExpand
1#include <allegro5/allegro.h> 2#include <allegro5/allegro_image.h> 3 4int main() 5{ 6 if(!al_init()) 7 exit(1); 8 if(!al_install_mouse()) 9 exit(-1); 10 al_init_image_addon(); 11 ALLEGRO_DISPLAY *display = al_create_display(800, 600); 12 ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue(); 13 ALLEGRO_TIMER *timer = al_create_timer( 1.0/60.0); 14 al_register_event_source(event_queue, al_get_mouse_event_source()); 15 al_register_event_source(event_queue, al_get_display_event_source(display)); 16 al_register_event_source(event_queue, al_get_timer_event_source(timer)); 17 18 ALLEGRO_BITMAP *quill = al_load_bitmap("quill.png"); 19 if(!quill) 20 exit(-2); 21 ALLEGRO_MOUSE_CURSOR *cursor = al_create_mouse_cursor(quill, 0, 0); 22 if(!cursor) 23 exit(-3); 24 al_set_mouse_cursor(display, cursor); 25 26 27 bool quit = false; 28 bool tick = false; 29 al_start_timer(timer); 30 while(!quit) 31 { 32 33 do 34 { 35 ALLEGRO_EVENT ev; 36 al_wait_for_event(event_queue, &ev); 37 switch(ev.type) 38 { 39 case ALLEGRO_EVENT_TIMER: 40 tick = true; 41 break; 42 case ALLEGRO_EVENT_DISPLAY_CLOSE: 43 quit = true; 44 break; 45 default: 46 break; 47 } 48 49 50 } 51 while(!al_event_queue_is_empty(event_queue)); 52 53 if(tick) 54 { 55 /* 'Quill' is being drawn to the screen 56 so the bitmap was loaded fine. */ 57 al_draw_bitmap(quill, 0, 0, 0); 58 al_flip_display(); 59 tick = false; 60 } 61 62 63 } 64 65 return 0; 66};

This code always returns -3. If I comment out the if block the loop runs fine and the bitmap I'm using for the cursor is drawn fine.

André Silva

The only thing I can think of real fast is that the bitmap might be too big. I really don't suppose it's because the hotspot is at 0,0, but just to make sure you cover everything, try setting it to like 2,3 (provided your bitmap is larger than 2x3 :P)

beoran

Could you please provide the bitmap also? TThen we could test the code in the same conditions as you do. Thanks!

hyreia77

Aah, my image was too big! I had assumed I could use a pretty large image (150 x 50 here) but it didn't like that. I'm ashamed this didn't occur to me.

Testing it now, whatever is responsible for rejecting the cursor size on a Windows7 build, at least on my computer, won't allow the image to be larger than 32 x 32. It doesn't have to be square, just neither dimension can be over 32.

A solution I'm considering now: just hiding the mouse and drawing a bitmap where the mouse cursor reports itself to be, image being drawn with an offset so the focus is at the mouse point.

Thanks for the brainstorm.

Thread #612933. Printed from Allegro.cc