Include ttf in exe
Bingocat

Is it possible to include a ttf file inside of the exe? Like how it's possible to include dll's in the exe. It would be nice to not have any files other than the exe.

RPG Hacker

Is it really favorable to include all resources in the EXE? That means that whenever you make an update for the game, people will have to redownload the whole game instead of just the executable. That is something that should be considered.

Don't know if this is possible. Probably as a resource file? Even then I don't know how you would load it with Allegro.

Niunio

Both versions 3 and 4 had utilities to translate data files into ASM and link with exe. I didn't see such stuff in version 5, but it can be reproduced and overload the file_io system to load data from byte arrays (for example).

But as RPG Hacker said, I find it useless except if you're doing something like a demo.

SiegeLord

With Allegro 5 you can use the xxd tool to convert your file to a C array and then the memfile addon (i.e. al_open_memfile).

torhu

Cool, xxd is even part of the Git for Windows package.

Bingocat

How to do you use al_open_memfile()? I can find no examples anywhere.

torhu
Bingocat

What are the arguments that you put in? Can you give me an example? Like if I have this array then how do I use the command to turn it into an ALLEGRO_FONT? Also, I'm not sure if I converted the .ttf file correctly or not. Should it be this length?

#SelectExpand
1char font[] = { 20x00,0x01,0x00,0x00,0x00,0x18,0x01,0x00,0x00,0x04, 30x00,0x80,0x44,0x53,0x49,0x47,0xB2,0x75,0xFB,0xD1, 40x00,0x0D,0x7F,0x70,0x00,0x00};

Edgar Reynaldo

Obviously, that char array does not hold the ttf file you converted. It would be orders of magnitude larger if it did.

The _f functions load from memory locations, using ALLEGRO_FILES's.

You want to use al_open_memfile and al_load_ttf_font_f.

Gideon Weems
SiegeLord said:

With Allegro 5 you can use the xxd tool to convert your file to a C array and then the memfile addon (i.e. al_open_memfile).

The xxd utility that comes with vim? I didn't realize that existed outside of Vi Land, though I see now that msys includes it.

Audric

You don't even need to generate such hefty C file, compilers can link binary files directly. For example with GCC, the utility is objcopy.
https://balau82.wordpress.com/2012/02/19/linking-a-binary-blob-with-gcc/

Bingocat

Ok this is the code that I tried, but there is still a problem. It says that the arial variable is being used before it's initialized. What am I doing wrong?

#SelectExpand
1ALLEGRO_FILE *arial = al_open_memfile(arial, 891469, "rw"); 2 3 ALLEGRO_FONT *font18 = al_load_ttf_font_f(arial, NULL, 18, NULL); 4 ALLEGRO_FONT *font10 = al_load_ttf_font_f(arial, NULL, 10, NULL);

Edgar Reynaldo

You're passing the wrong argument (or shadowing a variable (using the same name)) to al_open_memfile. Your ALLEGRO_FILE* and your argument to al_open_memfile have the same name ('arial'). I assume that's a typo. What is your memory block called? That is what you pass to al_open_memfile.

Thread #616474. Printed from Allegro.cc