I have a 114x114 bitmap called "x.bmp" in my debug folder and this simple code
#include <allegro.h>
BITMAP *Sprite;
int main(){
allegro_init();
install_keyboard();
set_color_depth(16);
set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);
Sprite = load_bitmap( "x.bmp", NULL);
acquire_screen();
draw_sprite(screen, Sprite, 50, 50);
release_screen();
readkey();
return 0;
}
END_OF_MAIN();
But it freezes up and looks like this
But when I just run the AllegroTest.exe
file via windows explorer it works...
I am using Allegro 4.2.3 and MSVC++ 2008
Edit: here's something interesting I get in my debug ou开发者_Go百科tput window:
al-gfx INFO: The driver will wait for vsync.
al-gfx INFO: set_gfx_card success for 640x480x16.
Assert failed at line 250 of c:\users\matthew\desktop\allegro\4.2\include\allegro\inline\draw.inlThe thread 'Win32 Thread' (0x137c) has exited with code -805306369 (0xcfffffff).
The thread 'Win32 Thread' (0x25b8) has exited with code -805306369 (0xcfffffff).
c:\users\matthew doesn't exist!!! I have no user named matthew?
The bitmap most likely can't be loaded.
When you start an application from the Visual Studio debugger, the default working directory is the project directory. When you start an application via explorer, the working directory is the directory the executable is in. Normally, the project directory will be ...\SolutionName\ProjectName\.
When you provide a relative path, i.e. x.bmp
, the application will search the working directory for it, followed by some other directories, such as those listed in the PATH environment variable. It's usually preferable to give an absolute path, if possible.
Most likely your image file is in the same directory as the executable, but this directory isn't the project directory.
精彩评论