Results 1 to 4 of 4

Thread: Compile resource file with exe

  1. #1
    Serf
    Join Date
    Aug 2011
    Posts
    3

    Default Compile resource file with exe

    I am using VC++ ultimate.

    I have png image files that is displayed in a game.
    But I don't want this images to be accessible to the players.

    How do I compile these images with the exe and display it in the program?

    Or can I encrypt the images?
    Last edited by byrandomby; 08-28-2011 at 06:10 AM.

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    It can be done.

    However, it can be tricky.

    This trick is to use: CL_IODevice_Memory ( http://clanlib.org/docs/clanlib-2.3/...e__Memory.html )
    and provide the raw binary data to it via CL_DataBuffer

    Unfortunately C++ does not provide an "incbin" function to link raw binary data into the application.

    A portable way is to run a program to convert a "png" from binary to a C++ char array (chay mypng[13242] = {0x44,0x24...} )
    But that is 1) not automatic. 2) create huge C++ files (with the limitation of /Zm (Specify Precompiled Header Memory Allocation Limit)

    If targeting visual studio, you can store the data in resource files. Note, there are tools to extract and edit the images.

    If targeting GCC, you can use "objcopy -B i386 -I binary -O elf32-i386 foo-data.bin foo-data.o " ... "extern uint8_t foo_data[] asm("_binary_foo_data_bin_start");" (from http://stackoverflow.com/questions/4...utable-library )

  3. #3
    Serf
    Join Date
    Aug 2011
    Posts
    3

    Default

    How do other game developers hide their game resources?

    For example, certain games have large .pak files (which I assume stores the resources).

    Can I do the same?

  4. #4
    Master Sorcerer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    A .pak file is actually just a zip file that has been renamed. So if you rename it back to .zip you could extract it and look at its contents.

    ClanLib supports a similar feature using the CL_VirtualFileSystem where you feed it a zip file and then use the VFS class when opening files. I.e. You can pass the vfs to CL_ResourceManager and that way load your resources from a zip archive. If you chose to use this method, you probably will want to create the zip file with no compression to minimize loading overhead. Or at least not compress the files that are already compressed by other means (images, ogg, etc).

    What rombust is talking about is to include the resources into the actual executable. I wouldn't recommend this, but if you for some reason really would have to do this, I would use a platform specific method like importing the zip as a win32 resource object in Windows and use FindResource to access it. However the only advantage of this is to have a self-contained .exe with no external dependencies and it has several drawbacks.

Similar Threads

  1. Not a valid XML resource file exception
    By alexv1 in forum Official ClanLib SDK Forums
    Replies: 7
    Last Post: 02-06-2009, 11:30 PM
  2. Problems with resource file
    By LonelyStar in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 04-26-2008, 12:25 PM
  3. custom resource
    By oilen in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 12-07-2007, 12:12 PM
  4. use zipped resource
    By DavinciZhe in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 10-20-2007, 07:59 PM
  5. resource.dat
    By redink1 in forum Other RTsoft Games
    Replies: 1
    Last Post: 11-15-2002, 10:08 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •