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".
EDIT: Problem solved.
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: