|
loading bitmaps with allegro |
blackwind87
Member #7,707
August 2006
|
Hello! #include <allegro.h> int set_graphic_mode() int main(int argc, char **argv) if (!set_graphic_mode()) BITMAP *bild = load_bitmap("ffx-2.bmp", NULL); acquire_screen(); while (!keypressed()); |
gnolam
Member #2,030
March 2002
|
1) Edit your post to use code tags. 2) Quote: But each time I start the exe-file there comes an error-message. What message? Always include all the relevant information when asking for help. 3) Quote: BITMAP *bild = load_bitmap("ffx-2.bmp", NULL); You need error checking. BITMAP *bild = load_bitmap("ffx-2.bmp", NULL); if (!bild) { allegro_message("Couldn't find ffx-2.bmp!\n"); exit(1); } 4) Quote: The bitmap is in the same directory like the .cpp and the .exe and I can't find the error in the programm, I hope you can help me. And are you running the program through the commandline or through an IDE of some kind? IDEs are notorious for using weird working directories. This will, however, be caught by 3) above. 5) Main should return 0. 6) Minor points: Quote: END_OF_MAIN(); Remove the semicolon (counter-intuitive, I know, but it's how the macro is constructed). b) acquire_screen() and release_screen() aren't necessary. Here, they just clutter up the code (and if you put anything not graphics related in between them, Bad ThingsTM happen to your program). -- |
Evert
Member #794
November 2000
|
You should check the return value of load_bitmap(). Quote: The bitmap is in the same directory like the .cpp and the .exe
That's probably irrelevant. The file needs to be in the current working directory when the program is run. |
LennyLen
Member #5,313
December 2004
|
What is the error message? Also, why on earth have you written your set_graphic_mode function the way you have? END_OF_MAIN() also does not have a semicolon at the end of it.
|
blackwind87
Member #7,707
August 2006
|
This program was an example in a book i buied and I thought it should work... |
LennyLen
Member #5,313
December 2004
|
Which book?... [cue spooky music]
|
blackwind87
Member #7,707
August 2006
|
It's a german book about programming with allegro but it is from the year 2003. I don't know the actual titel... |
LennyLen
Member #5,313
December 2004
|
Quote: It's a german book about programming with allegro but it is from the year 2003. Oh, I was expecting it to be another book notorious for bad coding practices. But hmmm, a German book on Allegro - Spellcaster's? (This question is directed at established a.cc members, not you blackwind.) Quote: The bitmap is in the same directory and the name is correct and so I don't understand, why it can't be found!? Well, as gnolam has already mentioned, some IDEs create their own working directories, so if you're attempting to run the program from the IDE, it may be looking in the working directory.
|
Evert
Member #794
November 2000
|
Quote: why on earth have you written your set_graphic_mode function the way you have?
What's wrong with it? Quote: [cue spooky music] Nah, the programming style is different. Besides, people who use GPAIO2E #include <conio.h> for no good reason. Quote: It's a german book about programming with allegro Ah, that would be spelly's book. Quote: buied bought. Quote: but now there comes the message that ffx-2.bmp couldn't be found. The bitmap is in the same directory and the name is correct and so I don't understand, why it can't be found!?
Because it needs to be in the active working directory when the program is run,which is not nescessarily the same as the directory that contains the executable. char name[200]; BITMAP *bild; get_executable_name(name, sizeof(name)); replace_filename(name, name, "ffx-2.bmp", sizeof(name)); bild = load_bitmap(name, NULL);
|
CGamesPlay
Member #2,559
July 2002
|
Quote: It's a german book about programming with allegro but it is from the year 2003. I don't know the actual titel... Spielenprogrammen mit Allegro (Lennart Steinke), isn't it? At least, that is the only one anyone at this forum will be familiar with Quote: I have fixed some things like described above, but now there comes the message that ffx-2.bmp couldn't be found. The bitmap is in the same directory and the name is correct and so I don't understand, why it can't be found!? What is the compiler you are using? As said, you have to actually run the program from the same directory as the image file is in. That means that if you double-click on the program icon, make sure the image is also in that Explorer window. Also, double-click on the image and make sure it loads properly. [append] Quote:
What's wrong with it? His code sets 3 different graphics modes, and 2 of them are the same mode -- Ryan Patterson - <http://cgamesplay.com/> |
LennyLen
Member #5,313
December 2004
|
Quote: What's wrong with it? Actually, nothing, I just REALLY didn't read it properly and somehow missed all the "return 1"'s (my excuse is that I've been awake for about 70 hours now and the lack of formatting was making my eyes bleed). It appeared he was setting the graphics mode to three different settings back-to-back. [edit] Quote: His code sets 3 different graphics modes, and 2 of them are the same mode Look again.
|
blackwind87
Member #7,707
August 2006
|
Okay, now there is the first message again: An unhandled win32 exception occured in prog4.exe[2988]. Just-In-Time debugging this exception failed with the following error: No installed debugger has Just-In-Time debugging enabled. In Visual Studio, Just-In-Time debugging can be enabled from Tools/Options/Debugging/Just-In-Time. But I doesn't have Visual Studio:o |
William Labbett
Member #4,486
March 2004
|
I've got the same problem tonight. I'm using Dev-C++ and I'm trying to load a bitmap and display it (shouldn't be too hard), but the program can't load it. Like Blackwind it's in the same dir as the .exe. Other programs have managed to load bitmaps like this (from the same dir as the .exe). But it's not working this time..???
|
Evert
Member #794
November 2000
|
Quote: it's in the same dir as the .exe Once again, it doesn't matter if it's in the same directory as the binary, it needs to be in the working directory. Check that it is and if it is, post the program and the image. |
William Labbett
Member #4,486
March 2004
|
actually i've found where the error is. i had the file name wrong in the code.
|
|