Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Loading textures from a zip archive  (Read 4866 times)

0 Members and 1 Guest are viewing this topic.

Lignum

  • Newbie
  • *
  • Posts: 20
    • View Profile
Loading textures from a zip archive
« on: January 29, 2015, 03:47:46 pm »
Hi!
Up until now I've been using OpenTK for rendering where I've been storing my textures in zip archives. This worked perfectly fine until I decided to switch to SFML.Net.

This is my code:
var tex = new Texture(loader.GetResourceAsStream(filename));
 
I'm using .NET 4.5's ZipArchive internally. loader is just a small interface I made for it.
With this I'm getting a NotSupportedException: "This stream from ZipArchiveEntry does not support seeking."

So I tried this:
byte[] data = loader.GetResourceAsByteArray(filename); // the array starts with "?PNG", so this is probably not the issue...
var tex = new Texture(new MemoryStream(data));
 
This one throws a LoadingFailedException: "Failed to load texture from memory."

Using zip files makes everything nice and simple so I'd hate to get rid of it. Is there any other way to do this?

Thanks in advance,
- Lignum

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Loading textures from a zip archive
« Reply #1 on: January 29, 2015, 04:38:36 pm »
I think you'll find that PhysFs (http://icculus.org/physfs/) does what you want.

Ztormi

  • Jr. Member
  • **
  • Posts: 71
  • Web developer by day. Game developer by night.
    • View Profile
Re: Loading textures from a zip archive
« Reply #2 on: January 29, 2015, 04:46:52 pm »
I'm going to take a wild guess and say this will fix it http://stackoverflow.com/questions/8741474/returning-a-stream-from-file-openread
« Last Edit: January 29, 2015, 05:00:30 pm by Ztormi »

Lignum

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Loading textures from a zip archive
« Reply #3 on: January 29, 2015, 05:45:07 pm »
I think you'll find that PhysFs (http://icculus.org/physfs/) does what you want.

Ah, yes it does. Thanks, I'll take a look at that at some point.

I'm going to take a wild guess and say this will fix it http://stackoverflow.com/questions/8741474/returning-a-stream-from-file-openread

With your solution it outputted an error saying that 8-bit images weren't supported. I updated the concerned images and it works now! Thanks for your help.