Author Topic: How to embed resources into you app  (Read 3238 times)

Harteex (OP)

  • * Administrator
  • Posts: 709
    • Harteex Productions
How to embed resources into you app
« on: October 19, 2009, 11:45:56 am »
This is written for development under Windows, but it shouldn't be hard to adapt this to a Linux environment.

An easy way to embed resources into the app is to use a utility often called bin2h to convert the binary files to a c header, and then include that header in your project.
A utility for this can be found here: exe, source

Then, if you don't want to specify each resource individually, and don't want multiple .h files, you can create a bat-file with:
Code: [Select]
DEL ..\src\images.h
FOR %%X IN (*.tga) DO bin2h %%X
FOR %%X IN (*.h) DO type %%X >> ..\src\images.h
DEL *.h

This piece of code creates individual .h files for each .tga file in the folder, and then creates a combined .h file in the src directory.

The code assumes that your folder structure is like the following:
- src
- res <-- here you have the bat file and your resources

Edit:
If you're looking for a tga loading function which takes an array generated by bin2h instead of a file, check out the SameGoo sources in graphics.c.
« Last Edit: October 19, 2009, 11:53:53 am by Harteex »

alekmaul

  • *
  • Posts: 330
    • Portabledev
Re: How to embed resources into you app
« Reply #1 on: October 19, 2009, 01:23:41 pm »
Thanks a lot for this tutorial.
Also, if someone knows how to find functions prototype in .a libraries, i think entry.a has some functions to manage resources like the standard s2dsdk lib.
Here are the name :         
  get_dl_handle
  dl_res_open
  dl_res_get_size
  dl_res_get_data
  dl_res_close