C/C++ Allegro 程序无法运行

发布于 2024-10-03 10:45:19 字数 801 浏览 7 评论 0原文

不会加载我的图片 我的默认错误消息是“加载图片.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

方觉久 2024-10-10 10:45:19

您将需要提供更多信息...

  • 您使用什么平台? (MS Visual C++?Linux?Mac?...)
  • 哪个版本的 Allegro? (我猜是 4.x)

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...

  • What platform are you using? (MS Visual C++? Linux? Mac?...)
  • Which version of Allegro? (I'm guessing 4.x)


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.

迷迭香的记忆 2024-10-10 10:45:19

我相信您的程序可能无法找到您尝试加载的位图图像。尝试在代码中插入位图的确切路径。

例如:

char*filename="C:\My Documents\Pictures\picture.bmp";

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:

char*filename="C:\My Documents\Pictures\picture.bmp";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文