allegro help

This topic is 4164 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I am using C++ and Allegro for this. I have created some games in Allegro but none have had any mouse support so now I am trying to do a simple test of the mouse and i cant seem to get it to work. It compiles fine but i get a runtime error. Can anyone maybe help me out here and tell me whats going on. when i debug it .. my program "craps out" at the lines of draw_sprite() and blit(). Im not sure where exactly the problem is. i had this posted in the beginners forum but got 0 replies so i figure i had it in the wrong forum. Ill try here.
#include <allegro.h>

BITMAP* buffer;
BITMAP* cursor;

int main()
{

allegro_init();
set_color_depth(24);
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
install_keyboard();
install_mouse();
install_timer();

buffer = create_bitmap(640,480);
clear_bitmap(buffer);

cursor = create_bitmap(16,16);
clear_bitmap(cursor);
cursor = load_bitmap("cursor.bmp", 0);

while(!key[KEY_ESC])
{
clear_bitmap(buffer);
textprintf(buffer, font, 10, 10, makecol(255,255,255), "x pos = %d   y pos = %d", mouse_x, mouse_y);

draw_sprite(buffer, cursor, mouse_x, mouse_y);
blit(buffer, screen , 0, 0, 0, 0, 640, 480);

}

destroy_bitmap(buffer);
buffer = NULL;
destroy_bitmap(cursor);
cursor = NULL;

allegro_exit();
return 0;
}

// Some Allegro magic to deal with WinMain().
END_OF_MAIN();



Share on other sites
Quote:
 cursor = create_bitmap(16,16);cursor = load_bitmap("cursor.bmp", 0);

That is a memory leak. load_bitmap() will create the bitmap automatically.

cursor = load_bitmap("cursor.bmp", 0);if (!cursor){  allegro_message("Unable to load cursor.bmp");  return 0;}

Share on other sites
The NULL assignments at the end are unnecessary too.

But yeah, looks fine beyond that. Make sure that bitmap loads up per konforce's check there ...

Share on other sites
thanks a bunch both of you!

I added the error checking code ( i need to get in the habit of that)

the removal of create_bitmap() fixed it thanks again.

Share on other sites
I have an Allegro question, and, not being able to register due to lack of email, I have to post it here, sorry. I can't figure out how to display variables, especially int and string variables, while I'm using allegro. Does it have to be an array of unsigned chars to display a string? Because that's the only method I've seen, and I don't know how to change the entire array for a new string. Please help me, after today I'll be without the internet for two weeks, so this is my last chance to find out. Sorry for the lengthy post.

Share on other sites
Basic stuff.

Reading the manual and checking the example code will get you far. Allegro comes with both, so read offline.

Closed for thread necro.

Share on other sites

This topic is 4164 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

This topic is now closed to further replies.