Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Include ttf in exe

This thread is locked; no one can reply to it. rss feed Print
Include ttf in exe
Bingocat
Member #15,424
December 2013

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
Member #12,492
January 2011
avatar

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
Member #1,975
March 2002
avatar

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.

-----------------
Current projects: Allegro.pas | MinGRo

SiegeLord
Member #7,827
October 2006
avatar

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).

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

torhu
Member #2,727
September 2002
avatar

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

Bingocat
Member #15,424
December 2013

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

torhu
Member #2,727
September 2002
avatar

Bingocat
Member #15,424
December 2013

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
Member #8,592
May 2007
avatar

Gideon Weems
Member #3,925
October 2003

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
Member #907
January 2001

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
Member #15,424
December 2013

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
Member #8,592
May 2007
avatar

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.

Go to: