Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Mouse bitmap

This thread is locked; no one can reply to it. rss feed Print
Mouse bitmap
motyas
Member #16,305
April 2016

Hello guys, someone know how to create a bitmap and attach it in the mouse?
Something like this:
https://www.youtube.com/watch?v=5uSEhm652SE&list=PL6B459AAE1642C8B4&index=12
The problem is that i have this code and i need to put the image here, but after several tests i can't do it yet...
This is the code:

#SelectExpand
1#include <iostream> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_native_dialog.h> 4 5const int screenHeight = 800, screenWidth = 572; 6 7int main(int argc, char *argv[]){ 8 9 ALLEGRO_DISPLAY *display = NULL; 10 ALLEGRO_EVENT_QUEUE *event_queue = NULL; 11 12 if(!al_init()) { 13 al_show_native_message_box(NULL, NULL, NULL, "Allegro 5 could not initialize successfully", NULL, NULL); 14 return -1; 15 } 16 17 display = al_create_display(screenHeight, screenWidth); 18 if(!display) { 19 al_show_native_message_box(display, "Sample Title", "Display Settings", "The window wasn't created successfully!", NULL, ALLEGRO_MESSAGEBOX_ERROR); 20 return -1; 21 } 22 23 event_queue = al_create_event_queue(); 24 if(!event_queue) { 25 fprintf(stderr, "failed to create event_queue!\n"); 26 al_destroy_display(display); 27 return -1; 28 } 29 30 al_register_event_source(event_queue, al_get_display_event_source(display)); 31 32 al_clear_to_color(al_map_rgb(0,0,0)); 33 34 al_flip_display(); 35 36 while(1) 37 { 38 ALLEGRO_EVENT ev; 39 ALLEGRO_TIMEOUT timeout; 40 al_init_timeout(&timeout, 0.06); 41 42 bool get_event = al_wait_for_event_until(event_queue, &ev, &timeout); 43 44 if(get_event && ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { 45 break; 46 } 47 al_clear_to_color(al_map_rgb(0,0,0)); 48 al_flip_display(); 49 } 50 51 al_destroy_display(display); 52 al_destroy_event_queue(event_queue); 53 54 return 0; 55}

Thanks ;D

torhu
Member #2,727
September 2002
avatar

motyas
Member #16,305
April 2016

I have this problems (i put the images of my problems in this reply) scuse me for do a lot of questions but i'm new in this and i couldn't find the answers in internet, Thanks for answer me anyway ;D

torhu
Member #2,727
September 2002
avatar

I can't see an al_draw_text call in your code, can you see in the debugger where it is? It looks like font is NULL, so something is probably not initalized. You could also look at the value of the ustr parameter, maybe it's an error message.

motyas
Member #16,305
April 2016

Mmmm... I don't know what's the problem :-/ i have the al_draw_text call, but I think is a problem with the files... ???

torhu
Member #2,727
September 2002
avatar

Are you calling al_draw_text, or is Allegro?

motyas
Member #16,305
April 2016

I think so... i think is the file that i include in Xcode, i don't have any problems with the other allegro functions, but i have problems with the images and with the fonts. I smell something fishy... ???

torhu
Member #2,727
September 2002
avatar

It's very hard to help if you don't provide any concrete information ;)

motyas
Member #16,305
April 2016

Ok, sorry for this hahah. The error that i have tell me this:

void al_draw_tinted_bitmap(ALLEGRO_BITMAP *bitmap, ALLEGRO_COLOR tint,
float dx, float dy, int flags)
{
ASSERT(bitmap);
al_draw_tinted_bitmap_region(bitmap, tint, 0, 0,
bitmap->w, bitmap->h, dx, dy, flags); // I have an error here... Thread 8: EXC_BAD_ACCESS(code = 1, address = 0x24)
}

This is my code (i did a new):

#SelectExpand
1#include <iostream> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_image.h> 4#include <allegro5/allegro_primitives.h> 5#include <allegro5/allegro_native_dialog.h> 6 7int main(int argc, char *argv[]){ 8 9 const int screenWidth = 640, screenHeight = 480; 10 11 ALLEGRO_DISPLAY * display = NULL; 12 ALLEGRO_EVENT_QUEUE * event_queue = NULL; 13 bool done = false; 14 15 int pos_x = screenWidth / 2, pos_y = screenHeight / 2; 16 17 if(!al_init()){ 18 al_show_native_message_box(NULL, NULL, NULL, "Allegro couldn't initialize successfully", NULL, NULL); 19 return -1; 20 } 21 22 display = al_create_display(screenWidth, screenHeight); 23 if(!display){ 24 al_show_native_message_box(NULL, NULL, NULL, "Display wans't created successfully", NULL, ALLEGRO_MESSAGEBOX_ERROR); 25 return -1; 26 } 27 28 al_init_image_addon(); 29 30 ALLEGRO_BITMAP * player = NULL; 31 player = al_load_bitmap("resources/player.png"); 32 33 event_queue = al_create_event_queue(); 34 35 al_register_event_source(event_queue, al_get_display_event_source(display)); 36 37 while(!done){ 38 ALLEGRO_EVENT ev; 39 al_wait_for_event(event_queue, &ev); 40 41 if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE){ 42 done = true; 43 } 44 45 al_draw_bitmap(player, pos_x, pos_y, NULL); 46 47 al_flip_display(); 48 al_map_rgb(0, 0, 0); 49 } 50 al_destroy_display(display); 51 52 return 0; 53}

This is all my information ;)

torhu
Member #2,727
September 2002
avatar

You should probably check the return value from al_load_bitmap.

motyas
Member #16,305
April 2016

What? Sorry, but i didn't understand ::)

torhu
Member #2,727
September 2002
avatar

Do something like this:

player = al_load_bitmap("resources/player.png");
if(!player){
    al_show_native_message_box(NULL, NULL, NULL, "Failed loading player.png", NULL, ALLEGRO_MESSAGEBOX_ERROR);
    return -1;
}

motyas
Member #16,305
April 2016

I did it, and i don't have any errors, but the window open and close instantly

torhu
Member #2,727
September 2002
avatar

Then you have to learn how to debug ;)

motyas
Member #16,305
April 2016

Solved, i haven't put the complete direction in the al_load_bitmap(file); hahaha (in the tutorial that i see it isn't necessary).
Thanks for the help! :)

torhu
Member #2,727
September 2002
avatar

Go to: