无法在 Allegro 5 中加载位图
在我的代码中,我有一个位图结构。
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)
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 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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您需要安装外部依赖项来加载 jpg 图像并将可执行文件与其链接。手册说:
请参阅:http://alleg.sourceforge.net/a5docs/5.0.3/ image.html
如果您还没有的话,您将需要
libjpeg
和libjpeg-dev
插件。在此处查找有关不同插件的一些信息:http://wiki.allegro。 cc/index.php?title=Install_Allegro5_From_SVN/Linux/Debian
I think you need to install external dependencies to load a jpg image and link your executable with it. The manual says:
See this: http://alleg.sourceforge.net/a5docs/5.0.3/image.html
You would need the
libjpeg
andlibjpeg-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
首先,您需要确保已编译支持 JPEG 的图像插件。在 Ubuntu 上,这意味着 libjpeg-dev。当使用 CMake 配置 Allegro 时,它会告诉您支持什么。如果您不记得了,请查看其日志文件。
另一个可能有问题的事情是相对路径。您确定您位于正确的位置吗?为了方便测试,请使用绝对路径,例如
"/home/me/game/foo.jpg"
。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"
.