c - 无法在 Allegro 5 中加载位图

标签 c allegro5

在我的代码中,我有一个位图结构。

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

有处理位图加载和绘制到屏幕的函数。

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;
}

当我使用位图加载的绝对路径或相对路径时,我总是得到这个输出。

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

我做错了什么?谢谢。 (操作系统:Ubuntu 10.10)

最佳答案

我认为您需要安装外部依赖项来加载 jpg 图像并将您的可执行文件与其链接。手册说:

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.

看这个:http://alleg.sourceforge.net/a5docs/5.0.3/image.html

如果您还没有,则需要 libjpeglibjpeg-dev 插件。在此处查找有关不同插件的一些信息:

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

关于c - 无法在 Allegro 5 中加载位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6097352/

相关文章:

c++ - Mac OSX 构建中缺少 Allegro 5.2 TTF 插件

c - C 中体系结构 x86_64 的 undefined symbol

c++ - 检查 C/C++ 中的数字是否为整数(不使用 scanf/gets/etc)

python - 在Python模块中调用C头文件函数

c - Visual Studio 似乎将 header 编译为 .c 文件

c - 如何在 Allegro 5 中以秒为单位计算时间

c - 在 C 中的函数调用中使用预增量是否错误?

c++ - 什么创建了堆栈?

C++ Allegro 5 - 找不到访问冲突的来源

c++ - allegro5 (C++) 中的另一幅图像