Joe
Joe

Reputation: 11

C/C++ Allegro program wont run

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()

Upvotes: 1

Views: 705

Answers (2)

THE DOCTOR
THE DOCTOR

Reputation: 4555

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

Upvotes: 0

Leftium
Leftium

Reputation: 17953

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.

Upvotes: 1

Related Questions