pouët.net

all-in-one-binary techniques

category: general [glöplog]
 
bin2c.com / bin2h.com / etc

I've seen these little tools used to embed files into a single executable.
It will convert the binary data to text, so you can include it in your sourcecode.
But...mostly this is done afterwards, because you will want to test your demo AND tweak your texture in Photoshop at the same time.

Another interesting (linuxonly) tool I saw is 'genromfs', you can call this in your makefile (taking a directoryname as argument), and then GCC will embed it into the binary.
When you do fopen("/rd/yourfile.tga"), it will act just like a disk.

MY QUESTION :

Are there any cool "crossplatform" (please forgive me) techniques for loading resources like this?

I like single-file-applications, but the bin2h-method is annoying when you have lotsa files!
added on the 2009-01-19 15:55:57 by squezel squezel
squezel:

stuff.asm:
Code: section .data: global _myvar _myvar incbin 'yourfile.tga'


or


stuff_with_size.asm:
Code: section .data: global _myvar _myvar incbin 'yourfile.tga' _myvar_end: global _myvar_size _myvar_size dd _myvar_end - _myvar

added on the 2009-01-19 16:01:59 by Gargaj Gargaj
oh and the above works with NASM.
added on the 2009-01-19 16:02:21 by Gargaj Gargaj
additionally, if you create a nicer .asm file with good macros, and a compile rule for raw files for visual studio, you can just drag files into your project, and they'll become raw data automatically
added on the 2009-01-19 16:04:00 by Gargaj Gargaj
the nicer asm file being

bin2obj.asm
Code:%macro include_binary 2 global %1 %1 incbin %2 %1_end: global %1_size %1_size dd %1_end - %1 %endmacro section .data include_binary OBJNAME, BINNAME


and the rule file (goes in C:\Program Files\Microsoft Visual Studio 8\VC\VCProjectDefaults\)

Code: <?xml version="1.0" encoding="utf-8"?> <VisualStudioToolFile Name="Raw data" Version="8,00" > <Rules> <CustomBuildRule Name="Raw Data" DisplayName="Raw Data Compiler" CommandLine="nasmw.exe -f win32 &quot;%NASMDIR%\bin2obj.asm&quot; -o $(OutDir)\$(InputName).obj -dOBJNAME=_$(InputName) -dBINNAME=\&quot;$(InputPath)\&quot;" Outputs="$(OutDir)\$(InputName).obj" FileExtensions="*.raw" ExecutionDescription="Compiling raw data..." > <Properties> </Properties> </CustomBuildRule> </Rules> </VisualStudioToolFile>
added on the 2009-01-19 16:05:34 by Gargaj Gargaj
what about ?

data.s:

.global DATA
.global ENDDATA
DATA: .incbin "my bloody data filename here"
ENDDATA:

(you'll have to re-assemble in a way or another in order to generate the .o again).
added on the 2009-01-19 16:06:36 by hitchhikr hitchhikr
fuck off gargaj :D
added on the 2009-01-19 16:06:56 by hitchhikr hitchhikr
i'm not sure that it works with .asm but using a .s and the gcc arguments parser will pass it directly to as so it can be added into a makefile without any effort.
added on the 2009-01-19 16:08:59 by hitchhikr hitchhikr
And if you don't like reassembling, you might try investigating the use of overlays for your operating system. When you do it correctly, you can attached arbitrary sized data-areas to your executable that would NOT be loaded when you load the application. The application would then search its own load-file to find its data-area. Obviously this requires some extra coding in your loading routines, but it can be fun and is worth the effort if you are really longing to have this feature. Also, I think you can just attach a Zip or Rar to your load-file, but I have never tried this for myself.
added on the 2009-01-19 16:15:32 by noname noname
I have my own bin2c and image2c programs. I use them in my makefile so that if i modify the source file, it automatically remakes the .c file and compiles it to an object.
added on the 2009-01-19 18:46:00 by xeron xeron
I don't bother, since it's a massive waste of time.
on some platforms you don't have much of a choice though...
added on the 2009-01-19 19:01:52 by raer raer

login