Allegro 5 - al_load_bitmap() not working!
Callum Gregg

Hi guys,

I have spent the past 5 hours fiddling around searching the web and the wiki to try and solve this problem I am having with al_load_bitmap.

I have moderate experience with C++ but this is my first time using the allegro library so I dont know a great deal about this but regardless of what I do I cannot get al_load_bitmap() to work.

At the moment I'm just trying to place bitmaps on the screen and regardless how basic I make the code I can't get it to work, can anyone spot something i'm doing wrong perhaps?

Even this basic code won't work:

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_image.h> 4 5int main(int argc, char **argv) 6{ 7 al_init(); 8 9 al_init_image_addon(); 10 11 ALLEGRO_BITMAP *bmp = al_load_bitmap("LowerFull.bmp"); 12 if(!bmp) 13 fprintf(stderr,"failed to load bitmap.\n"); 14 15 while(true){ 16 ... 17 } 18}

Any help would be greatly appreciated, Thanks! :)

Edit: I have also tried using an absolute path and that does not work either.

Matthew Leverton

What part doesn't work?

Callum Gregg

I always receive NULL for my bmp variable.

Edit:

Aha! I have finally got it to work!
I saw another post by you discussing a similar topic where you suggested the following code:

#SelectExpand
1ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH); 2al_set_path_filename(path, "LowerFull.bmp"); 3 4bmp = al_load_bitmap(al_path_cstr(path, '/'));

I'm assuming then the error was simply in pointing to the file? Yet this seems odd as an absolute address didn't work either!

North~

I've seen that question and solution so many times. Someone just needs to put that in the manual somewhere. ALWAYS USE al_get_standard_path(ALLEGRO_RESOURCES_PATH);

Matthew Leverton

Yet this seems odd as an absolute address didn't work either!

You probably used back slashes like "c:\foo\bar.png" when it should be "c:/foo/bar.png".

Note that you can also do this:

ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
chdir(al_path_cstr(path, '/'));
al_destroy_path(path);

bmp = al_load_bitmap("LowerFull.bmp");

Callum Gregg

Hmm, I am actually still having issues with this, it works for loading one of my bitmaps but not the others, the code is practically identical I'm not sure where I could be going wrong!

I can load in LowerFull.bmp but it wont let me load in LowerHalf.bmp, they are both in the same directory so I can't understand where the problem is.

If I print out the string it shows the correct directory for both yet the second returns false and if I try to draw it gives me an Access Violation error.

Any more ideas?

Matthew Leverton

How big are the bitmaps?

Callum Gregg

The bitmaps are 100kb and 200kb in size, the larger one has no problem loading, while the bigger one does.

Arthur Kalliokoski

The bitmaps are 100kb and 200kb in size.

I thought they had to be powers-of-two for dimensions, at least on some older cards. Those sizes don't strike me as fitting that criteria.

Callum Gregg

Ah, perhaps, I have quite a modern graphics card however, but how would I go about optimizing the bitmaps for that then?

Oh sorry, the exact size is 332kb for LowerFull.bmp and 111kb for LowerHalf.bmp

Arthur Kalliokoski

You'd set the dimensions in the bitmap editor to have the vertical and horizontal sizes to be powers-of-two, preferably 2048 or less. (MSPaint, paint.net or whatever you're using)

J-Gamer

EDIT: beaten...

Callum Gregg

Should I also destroy every bmp and path after I have used it? (I know its good practise to free up memory but are there any more implications caused by not deleting a bitmap/path from memory and trying to replace the same variable with another bitmap/path?)

Edgar Reynaldo

I thought Allegro 5 automatically took care of any problems with NPOT (non power of two) textures by making them powers of two if NPOT is not supported.

Yes, you should destroy bitmaps when you are done with them. You can ignore this, but then you are leaking memory that you may need later.

Matthew Leverton

The bitmaps are 100kb and 200kb in size, the larger one has no problem loading, while the bigger one does.

File size doesn't really matter, but the dimensions do. The height and width must be no larger than whatever your video card supports. Otherwise, you will have to load it as a memory bitmap (which is very slow).

They don't have to be a power of two.

Arthur Kalliokoski

OTOH, 2048 x 2048 = 4,194,304 (well over 4000k) even for 8 bit color without header info.

Thomas Fjellstrom

They don't have to be a power of two.

Some cards/drivers are moronic though, by advertising NPOT support, but doing it in software.

Thread #607748. Printed from Allegro.cc