开发者

unable to load bitmaps in Allegro 5

in my code I have a struct for bitmaps.

struct bat 
{
 float x;
 float y;
 ALLEGRO_BITMAP *bmp;
};

There are functions that handle loading and drawing the bitmaps to screen.

ALLEGRO_DISPLAY *display;

bool init_display(void)
{
   puts("-- initializing display. --");
   display = al_create_display(display_width, display_height);
   if(display)
   {
     al_clear_to_color(al_map_rgb(0,0,0));
     queue = al_create_event_queue();
     al_register_event_source(queue, al_get_display_event_source(display));
     if(init_objects()){return true; puts("-- display initialized. --");}
     else return false;
   }
   else return false;
}

bool create_bat(struct bat *bat, float x_coord, float y_coord, const char *path)
{   
    puts("-- creating bat. --");
    bat->x = x_coord;
    bat->y = y_coord; 
    bat->bmp = al_load_bitmap(path);
    if(bat->bmp){puts("-- bat created. --"); return true;}
    else return false;
}

struct bat bat; 

bool init_objects(void)
{
   puts("-- initializing objects. --");
   if(al_init_image_addon())
   {
      al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
      al_set_target_backbuffer(display);
      if(!create_bat(&bat, 0, 0, "img.jpg"))
      { puts("-- creating bat failed. --"); return false;}
      puts("-- objects initialized. --"); 
      return true;
   }
else return false;
}

I'm always getting this output when开发者_Go百科 I use an absolute path for the bitmap to load or a relative one.

-- initializing display. --
-- initializing objects. --
-- creating bat. --
-- creating bat failed. --

What am I doing wrong? Thanks. (OS: Ubuntu 10.10)


I think you need to install external dependencies to load a jpg image and link your executable with it. The manual says:

The following types are built into the Allegro image addon and guaranteed to be available: BMP, PCX, TGA. Every platform also supports JPEG and PNG via external dependencies.

See this: http://alleg.sourceforge.net/a5docs/5.0.3/image.html

You would need the libjpeg and libjpeg-dev addon if you still do not have. Find some information about the different addons here:

http://wiki.allegro.cc/index.php?title=Install_Allegro5_From_SVN/Linux/Debian


First off, you need to make sure you've compiled the image addon with JPEG support. On Ubuntu, that means libjpeg-dev. When configuring Allegro with CMake, it would have told you what was supported. Look at its log file if you don't remember.

The other thing that can be problematic is the relative path. Are you sure you are in the proper location? To easily test, use an absolute path like "/home/me/game/foo.jpg".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜