C/C++ Allegro 程序无法运行
不会加载我的图片 我的默认错误消息是“加载图片.bmp 时出错”每次都会弹出并且无法运行
#include "allegro.h"
int main(void)
{
char*filename="picture.bmp";
BITMAP*image;
int ret;
allegro_init();
install_keyboard();
set_color_depth(32);
ret=set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,480,0,0);
if(ret!=0)
{
allegro_message(allegro_error);
return 1;
}
image=load_bitmap(filename,NULL);
if(!image)
{
allegro_message("error loading %s",filename);
return 1;
}
blit(image,screen,0,0,0,0,SCREEN_W,SCREEN_H);
destroy_bitmap(image);
textprintf_ex(screen,font,0,0,1,-1,"%dx%d",SCREEN_W,SCREEN_H);
while(!keypressed());
allegro_exit();
return 0;
}
END_OF_MAIN()
wont load my picture
my default error message which is"error loading picture.bmp" pops up every time and wont run
#include "allegro.h"
int main(void)
{
char*filename="picture.bmp";
BITMAP*image;
int ret;
allegro_init();
install_keyboard();
set_color_depth(32);
ret=set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,480,0,0);
if(ret!=0)
{
allegro_message(allegro_error);
return 1;
}
image=load_bitmap(filename,NULL);
if(!image)
{
allegro_message("error loading %s",filename);
return 1;
}
blit(image,screen,0,0,0,0,SCREEN_W,SCREEN_H);
destroy_bitmap(image);
textprintf_ex(screen,font,0,0,1,-1,"%dx%d",SCREEN_W,SCREEN_H);
while(!keypressed());
allegro_exit();
return 0;
}
END_OF_MAIN()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将需要提供更多信息...
Assuming your question is, "How do I get my Allegro program to display my bitmap as intended," try to
确保生成的可执行文件和 picture.bmp 位于同一目录中。我的猜测是您在 Windows 上使用某种类型的 Microsoft IDE,并且尝试从 IDE 中运行该程序(例如通过调试菜单或按 F5)生成的可执行文件被放入特殊的输出目录中。它找不到您的 picture.bmp 文件。
或者,您可以尝试提供 picture.bmp 文件的完整路径。不过,您应该只使用此方法来查看这是否确实是问题所在。
You're going to need to provide some more information...
Assuming your question is, "How do I get my Allegro program to display my bitmap as intended," try to
Make sure the resulting executable file and picture.bmp are in the same directory. My guess is you are using some type of Microsoft IDE on Windows and you are trying to run the program from within the IDE (like via the debug menu or pressing F5) The resulting executable is put in a special output directory. It can't find your picture.bmp file.
Alternatively, you can try providing the full path to your picture.bmp file. You should only use this method to see if this is indeed the problem, though.
我相信您的程序可能无法找到您尝试加载的位图图像。尝试在代码中插入位图的确切路径。
例如:
I believe your program might not be able to locate the bitmap image you are attempting to load. Try inserting the exact path to your bitmap in your code.
For example: