John
John

Reputation: 105

How to use GIFs in Allegro 5 with the Algif5 addon?

I try to use this: https://github.com/allefant/algif5 but this doesn't work.

#include "algif.h"

char const* pathBoss1 = "boss1.gif";
ALGIF_ANIMATION *boss1Gif = NULL;
boss1Gif = algif_load_animation(pathBoss1);
// in a function: 
al_draw_bitmap(algif_get_bitmap(bossGif, al_get_time()), boss.x, boss.y, 0);

It throws lots of bugs like this

Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol _algif_get_bitmap referenced in function "void __cdecl drawBoss(struct Boss &,struct ALGIF_ANIMATION *)" (?drawBoss@@YAXAAUBoss@@PAUALGIF_ANIMATION@@@Z) LearnAllegro C:\Users\User\source\repos\LearnAllegro\LearnAllegro\LearnAllegro.obj 1

As if the library was not found. (I put all the downloaded files into ProjectName>ProjectName as there are other .h files there)

What should I do?

Upvotes: 0

Views: 952

Answers (2)

John
John

Reputation: 105

The library did not work for me and I ended up inputting gif frames separately. This for loop I used might help you: A simplified version:

for (int i = 0; i < maxFrameBoss1; i++) {
    std::string filename;
    filename = "boss1//frame_" + std::to_string(i) + "_delay-0.03s.png";


    boss1Image[i] = al_load_bitmap(filename.c_str());
    if (!boss1Image[i]) {
        fprintf(stderr, "failed to create boss1Image bitmap!\n");
        return -1*i;
    }
}

Make sure to include this at the beginning of your program:

#include <iostream>
#include <string>

Upvotes: 0

allefant
allefant

Reputation: 69

There is no official library - instead you need to add algif.c, bitmap.c, gif.c and lzw.c to your source files.

Alternatively if you know how to create a library you can create a library out of those 4 files and then link against that library.

Upvotes: 1

Related Questions