Jump to content
  • Advertisement
Sign in to follow this  
rherm23

allegro help

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

If you intended to correct an error in the post then please contact us.

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();



thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
Quote:

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

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

Add this to your code:

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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!