File Archive for images

edited April 2011 in General discussions
Hello everybody,

I'd like to know if anyone here has used an archive for your game images. Something like the PhysicsFS library.

The thing is, my game will have some images that I don't want to simply let them in a data directory so anyone could see them. It would be some kind of a spoiler.

how difficult would it be to implement something like that in orx?



  • edited April 2011
    I thought many times of using PhysicsFS for orx's package modules but always stumbled upon some difficulties (especially for handling all the data, including sound streaming) as there isn't only one function to access files on disk as every external dependency has it's own way to do it. Also I don't think PhysicsFS supports all the platform orx currently supports but I might be wrong on that point. I wasn't all that motivated either as PhysicsFS doesn't accept password protected archives and it always bugged me.

    Then I got distracted with something else, like unicode support or font generation, can't remember.

    In your case though, you can load the texture yourself with PhysicsFS to memory and then create the texture manually (look at how it's done for the default font texture in orxFont.c for example). It's not too bad.

    Another (easier) option that wouldn't involve any external library would be to apply a xor filter, for example, to all your textures for example and reprocess them when they're loaded in orx, this way the versions on file will just look like garbage. In this case you let orx load all his stuff by himself, then when you get the orxOBJECT_EVENT_CREATE event, you look at its content, if it's a texture you haven't processed yet, then do it now. I can help with that process by adding events for texture creation/deletion which would allow you to process them without any other consideration to take.
  • edited April 2011
    Your considerations about the PhysicsFS lib are relevant.

    I think your xor filter suggestion is good enough. So if you can add those events for texture creation/deletion, that would be great.

    So, after a texture creation event is triggered, how can I access the texture data?
  • edited April 2011
    It's in, but untested. :)

    Just ignore the first few create event as they'll be for internal textures used by orx (screen, pixel, default font), but you can easily filter them out using their name (probably empty).
  • edited April 2011
    Sorry, just realized I didn't answer your last question! ^^

    So here it is:
    orxFLOAT fWidth, fHeight;
    orxU8 *pu8Data;
    orxU32 u32BitmapSize;
    orxTEXTURE *pstTexture = orxTEXTURE(_pstEvent->hSender);
    orxBITMAP *pstBitmap = orxTexture_GetBitmap(pstTexture);
    orxDisplay_GetBitmapSize(pstBitmap, &fWidth, &fHeight);
    u32BitmapSize = (orxU32)(fWidth * fHeight * sizeof(orxRGBA));
    pu8Data = (orxU8 *)orxMemory_Allocate(u32BitmapSize, orxMEMORY_TYPE_MAIN);
    orxDisplay_GetBitmapData(pstBitmap, pu8Data, u32BitmapSize);
    // Do your filtering
    orxDisplay_SetBitmapData(pstBitmap, pu8Data, u32BitmapSize);
  • edited April 2011
    Ok iarwain, thanks.

    I tried applying the filter, but I'm having a little trouble and I think it is because I'm trying to apply the filter in a png image. As png images are compressed, I think I can't just load the texture, apply the filter and save it. Am I right?
  • edited April 2011
    Well, you can use any capable image processing tool to do that and save them after your change.
    Or you can use orx to load the texture, modify them and save them back.

    This is very easy and require not much code but you can't save the texture back to .png as orx only supports writing tga, bmp or dds files. You then have to batch convert your images back to png using something like image magick or xnview. Not very handy I admit, I should look into supporting saving png files (but libpng is a bit of a mess).
  • edited May 2011
    Yeah, I remember reading somewhere that orx only saves to those formats, but I totally forgot about that. That was the problem, I was trying to save as png with orx. Now it is working.

Sign In or Register to comment.