0

I'm developing a game in Allegro 5.0.8, and everything was going well, until i tried compiling it and running it on Linux (Mint 14)...so i did sime tests;

#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>
#include <iostream>

int main(void)
{
    al_init();
    ALLEGRO_DISPLAY *screen = al_create_display(800, 600);
    al_init_image_addon();

    ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
    al_set_path_filename(path, "players.png");
    ALLEGRO_BITMAP *img = al_load_bitmap(al_path_cstr(path, '/'));

    if (img == NULL)
        std::cout << al_path_cstr(path, '/') << std::endl;

    al_draw_bitmap(img, 0, 0, 0);
    al_flip_display();

    while (true){}
    return 0;
}

this example compiles just fine, but the line

ALLEGRO_BITMAP *img = al_load_bitmap(al_path_cstr(path, '/'));

returns NULL. On the other hand, the line

std::cout << al_path_cstr(path, '/') << std::endl;

prints the exact absolute path of the image.

What am i doing wrong?

Sylar
  • 357
  • 1
  • 5
  • 15
  • PNG files are supported via external libraries, do you have e.g. `libpng` installed? – Some programmer dude Feb 01 '13 at 11:10
  • i have libpng12-0 ..but not libpng12-dev...should i install that too?? – Sylar Feb 01 '13 at 11:14
  • Yes you probably need that too, and to link with `libpng` (i.e. `-lpng`) as well. – Some programmer dude Feb 01 '13 at 11:17
  • i tried, and it still returns NULL...on the other hand i tried with a bmp, and it works...so, what am i doing wrong?? ...to compile i use: **g++ *.cpp -o test -lpng12 `pkg-config --libs allegro-5.0 allegro_image-5.0`** ...i tried also -libpng – Sylar Feb 01 '13 at 11:25
  • You should check what error you get, either with [`allegro_error`](https://www.allegro.cc/manual/4/api/using-allegro/allegro_error) or with [`errno`](http://en.cppreference.com/w/c/error/errno). – Some programmer dude Feb 01 '13 at 11:31
  • i don't really know how to use those, but when the program crashes i get **bitmap.c:315: al_draw_tinted_bitmap: Assertion `bitmap' failed.** – Sylar Feb 01 '13 at 11:39
  • `allegro_error` is a string you can print out directly, while `errno` is an integer, but you can use the [`strerror`](http://en.cppreference.com/w/c/string/byte/strerror) function to get a string from that (e.g. `strerror(errno)`). – Some programmer dude Feb 01 '13 at 11:47
  • so, where should i check for the error? ...because on the line **al_draw_bitmap(img, 0, 0, 0);** the program crashes, because of img being NULL – Sylar Feb 01 '13 at 11:57
  • It crashes because you pass a `NULL` pointer to the function. If the pointer is `NULL` don't call the function. You already check for error, in the `if` statement, in there _also_ print out the possible error messages and then exit the program (or do something else). But whatever you do, do not use a `NULL` pointer except to check if it's `NULL`. – Some programmer dude Feb 01 '13 at 12:02

1 Answers1

0

i have libpng12-0 ..but not libpng12-dev...should i install that too??

After you install libpng12-dev, you'll need to rebuild Allegro. The output of cmake tells you whether or not PNG is supported.

Once you rebuild Allegro with PNG support, it will work assuming your PNG file is not too big to load onto your video card.

Matthew
  • 47,584
  • 11
  • 86
  • 98