allegro5 C ++ al_load_bitmap崩溃程序并拒绝工作

时间:2016-01-17 03:05:53

标签: c++ mingw codeblocks allegro allegro5

我对allegro5有一个非常奇怪的问题。我正在尝试使用al_load_bitmap绘制位图。当我用一个示例程序对它进行测试时,我从allegro wiki中进行了测试,它运行得很好,并显示了位图。不幸的是,一旦我开始尝试创建自己的程序,它与示例程序非常相似,程序每次遇到al_load_bitmap时都会崩溃。我试图找出我的程序和示例程序之间的不同之处。

// The example program:
#include "allegro5/allegro.h"
#include "allegro5/allegro_image.h"
#include "allegro5/allegro_native_dialog.h"

int main(int argc, char **argv){

    ALLEGRO_DISPLAY *display = NULL;
    ALLEGRO_BITMAP  *image   = NULL;

    if(!al_init()) {
        al_show_native_message_box(display, "Error", "Error", "Failed to 
            initialize allegro!" NULL, ALLEGRO_MESSAGEBOX_ERROR);
            return 0;
    }

    if(!al_init_image_addon()) {
        al_show_native_message_box(display, "Error", "Error", "Failed to      
            initialize al_init_image_addon!", NULL, ALLEGRO_MESSAGEBOX_ERROR);
            return 0;
    }

    display = al_create_display(800,600);

    if(!display) {
        al_show_native_message_box(display, "Error", "Error", "Failed to 
            initialize display!", NULL, ALLEGRO_MESSAGEBOX_ERROR);

            return 0;
    }

    image = al_load_bitmap("image.png");

    if(!image) {
        al_show_native_message_box(display, "Error", "Error", "Failed to load 
            image", NULL, ALLEGRO_MESSAGEBOX_ERROR);
            al_destroy_display(display);
        return 0;
    }

    al_draw_bitmap(image,200,200,0);

    al_flip_display();
    al_rest(2);

    al_destroy_display(display);
    al_destroy_bitmap(image);

    return 0;
}

我的节目:

#include <allegro5\allegro.h>
#include <allegro5\allegro_primitives.h>
#include <allegro5\allegro_image.h>
#include "allegro5/allegro_native_dialog.h"         

int main(void)
{
    int width = 640;
    int height = 480;

    ALLEGRO_DISPLAY *display = NULL;
    ALLEGRO_BITMAP *image = NULL;

    if(!al_init())                                      //initialize Allegro
        return -1;

    if(!al_init_image_addon()) {
        al_show_native_message_box(display, "Error", "Error", "Failed to 
            initialize al_init_image_addon!", NULL, ALLEGRO_MESSAGEBOX_ERROR);

            return 0;
    }

    display = al_create_display(width, height);

    if(!display)                                        
        return -1;

    image = al_load_bitmap("orange.jpg");

    if(!image) {
        al_show_native_message_box(display, "Error", "Error", "Failed to load     
            image!", NULL, ALLEGRO_MESSAGEBOX_ERROR);

            al_destroy_display(display);
        return 0;
    }

    al_clear_to_color(al_map_rgb(0, 255, 0));

    al_draw_bitmap(image, 0, 0, 0);

    al_flip_display();

    al_rest(5);

    al_destroy_display(display);
    al_destroy_bitmap(image);                       //destroy our display object

    return 0;
}

0 个答案:

没有答案