Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » An example of using load_bitmap

This thread is locked; no one can reply to it. rss feed Print
An example of using load_bitmap
ibse12
Member #22,686
March 2022

I downloaded allegro-4.4.3.1 and I am trying to load bmp file via load_bitmap():

#SelectExpand
1#include <allegro.h> 2#include <stdio.h> 3int main(void) 4{ 5 BITMAP* b = load_bitmap("/home/ibse/alexlogo.bmp", NULL); 6 return 0; 7}

but get Segmentation fault error. The backtrace is

#SelectExpand
1Program terminated with signal SIGSEGV, Segmentation fault. 2#0 0x00007f6b7472c204 in create_bitmap_ex (color_depth=8, width=128, height=128) at /home/ibse/Downloads/allegro-4.4.3.1/src/graphics.c:1042 31042 if (system_driver->create_bitmap) 4(gdb) bt 5#0 0x00007f6b7472c204 in create_bitmap_ex (color_depth=8, width=128, height=128) at /home/ibse/Downloads/allegro-4.4.3.1/src/graphics.c:1042 6#1 0x00007f6b7470a97b in load_bmp_pf (f=f@entry=0x55da0b8775a0, pal=0x7ffdb59aa5e0, pal@entry=0x0) at /home/ibse/Downloads/allegro-4.4.3.1/src/bmp.c:699 7#2 0x00007f6b7470b58d in load_bmp (filename=<optimized out>, pal=0x0) at /home/ibse/Downloads/allegro-4.4.3.1/src/bmp.c:611 8#3 0x00007f6b7474e241 in load_bitmap (filename=0x55da0b373bc2 "/home/ibse/alexlogo.bmp", pal=0x0) at /home/ibse/Downloads/allegro-4.4.3.1/src/readbmp.c:81 9#4 0x000055da0b365e96 in main () at /home/ibse/Downloads/allegro-4.4.3.1/demos/skater/source/skater.c:5

Could anyone provide me with an example of how to use this routine correctly?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Mark Oates
Member #1,146
March 2001
avatar

You need to start with use allegro_init.

If you were using Allegro 5, you would use al_init. An,d because you are loading a PNG image you would need to al_init_image_addon().

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Chris Katko
Member #1,881
January 2002
avatar

Please stop using Allegro 4. It was made for DOS games. Like 20 years ago. In 99.99999% of all cases, you can "emulate" the feel of DOS in a proper Windows/Linux/Mac application.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Go to: