0

My problem is I can't load bitmap to allegro after compiling windows stops working. I tried different bitmaps with different color depths but it still doesn't work.

#include <allegro.h>

int main(int argc, char *argv[])
{
  allegro_init();
  install_keyboard();

  set_color_depth(16);
  set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0,0);
  set_window_title("The Game");

  BITMAP *bmp = create_bitmap(800,600);
  clear_bitmap(bmp);
  BITMAP *BG = load_bitmap("tlotlo.bmp",NULL);

  while(!key[KEY_ESC])
  {
  blit(bmp, screen, 0,0,0,0, bmp->w, bmp->h);
  blit(BG, bmp, 0,0,0,0, BG->w, BG->h);
  }

  destroy_bitmap(bmp);
  destroy_bitmap(BG);


  return 0;


}
END_OF_MAIN();
Higeath
  • 47
  • 3
  • 14

1 Answers1

0
  1. Use set_color_depth(desktop_color_depth())

  2. You aren't checking return codes. If create_bitmap or load_bitmap fail, they will return NULL and you'll need to deal with that accordingly.

  3. Loading a bitmap will fail if you aren't in the proper directory. You can test that out by using a full path to the bitmap. If a full path fixes the problem, then you should reconfigure your IDE to work properly.

  4. It's possible that the BMP file is not supported by Allegro. Allegro 4's BMP loading code cannot load more "modern" versions of the format. If you're just getting started, you should really use Allegro 5 instead.

Matthew
  • 47,584
  • 11
  • 86
  • 98