Trouble loading a .bmp using Allegro.


SoulFire9001

Member
Joined
Feb 16, 2012
Messages
108
Hello, I'm fairly new to coding on Linux, but I'm having problems loading a .bmp file that is located in the same directory as my .exe file. I have tried both just the .bmp name, and the full directory of the .bmp (which in my case would be in /media/SD_CARD/pandora/apps/allegtest/bitmapfilename). I'm running the program through CDevTools, and compiling it with: g++ -g main.cpp -o test1 -Wall -lalleg.


This is the code: I know it looks weird seeing only one place where I check for errors. I first wrote it as a test, then I was getting a segmentation fault after running, and it happened to be "test".

Code:
//Allegro on Pandora Test

#include <allegro.h>

#include <stdlib.h>

int main()

{

		 allegro_init(); //initialises Allegro for use

		 install_keyboard(); //install the keyboard handler

		 set_color_depth(16); //sets the global color depth

		 set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 480, 0, 0); //creates the graphics mode

		 BITMAP* buffer = create_bitmap(SCREEN_W, SCREEN_H); //declares and initialises a buffer BITMAP with the size of the screen.

		 BITMAP* test = load_bitmap("test.bmp", NULL); //again, also tried full directory. loads a local bitmap file called "test.bmp."

if(test == 0) {allegro_message("Cannot find test.bmp!"); exit(1);} //pop up window with a message if test.bmp cannot be found.

		 while(!key[KEY_SPACE]) //loops until the user presses the space key.

		 {

				 blit(test, buffer, 0, 0, 0, 0, test->w, test->h); //draw the test bitmap to the buffer bitmap

				 acquire_screen(); //lock the screen before drawing onto it.

				 blit(buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h); //draw the buffer to the screen.

				 release_screen(); //release the screen after drawing is done.

				 clear(buffer); //clear the buffer to a blank state.

		 }

		 destroy_bitmap(test); //free the memory when done to avoid memory leaks.

		 destroy_bitmap(buffer); //freeing memory.

		 return 0;

}

END_OF_MAIN()


EDIT: Problem solved.
 
Last edited by a moderator:
Knowing nothing about Allegro; Made sure its filename matches case-perfect to what you try to open? file.end is a different filename compared to File.end.
 
Knowing nothing about Allegro; Made sure its filename matches case-perfect to what you try to open? file.end is a different filename compared to File.end.
Yes, I usually name everything in lower case for easier use.
 
Last edited by a moderator:
What do you get if you just "fopen()" your bitmap? Does it return a valid handle?
 
What do you get if you just "fopen()" your bitmap? Does it return a valid handle?
It does actually. Hmm... I used:

Code:
char name[200];


 . . .


get_executable_name(name, sizeof(name)); //this gives the exact directory the program is being run in. For me it was /media/SD_CARD/pandora/apps/allegtest/test1 <-- that being the name of the exe.

replace_filename(name, name, "test.bmp", sizeof(name)); //this replaces the filename within 'name' with the full directory where the specified file is found (if it is found).

FILE *f_test = fopen(name, "r"); //open the bitmap through the full directory held within 'name'.

if (f_test == NULL) {allegro_message("The specified file for f_test was not found!"); exit(1);} //If it is NULL, print it out. But it is found, so no message from this line.

BITMAP *test = load_bitmap(name, NULL); //attempt to load the bitmap.

if (test == NULL) {allegro_message("test.bmp was not found!"); exit(2);} //the program exits here printing out the message.


try using " BITMAP* test = load_bitmap("./test.bmp", NULL);"
That didn't work for me. I set chmod a+r test.bmp as well and same thing happened.
 
Last edited by a moderator:
Hmmm, maybe it's something to do with your bitmap, is it really saved as a bitmap? not just named wrong? what colour depth (bpp)? dimensions? etc.
 
Hmmm, maybe it's something to do with your bitmap, is it really saved as a bitmap? not just named wrong? what colour depth (bpp)? dimensions? etc.
Welp, that was the problem. It seems the Famitsu chibi generator will save as a png even if you specify .bmp upon downloading. I made a quick bitmap on my netbook and it worked fine for me.
 
Back
Top