SFML community forums
Help => System => Topic started by: Bizarreofnature on February 05, 2018, 10:27:44 pm
-
Hello!
When it comes to streams and stuff im kinda helpless.
Im searching for an easy way to load for example .tga files from a zip file.
Forgive me for being such a noob.
Ive googled hours and checked every single thread in subforum System.
Without success of course.
Thanks in advance!
Best regards,
Bizarreofnature
-
See https://icculus.org/physfs/ and https://github.com/SFML/SFML/wiki/Source:-PhysicsFS-Input-Stream
The code on wiki is mine from a few years ago and a bit bad. I might rewrite it today. Done.
-
Sorry for late respond and thank you very much for your help. This is awesome. So easy.
But I have a problem. I cant find this file:
#include "PhysFsStream.hpp"
-
The wiki page has 3 files in it: PhysFsStream.hpp, PhysFsStream.cpp and example.cpp. You should create all three and copy the contents from it. You'll also need to get physfs library itself from somewhere else too (easiest is to build it yourself, since it doesn't provide prebuilt packages for a while now).
-
You'll also need to get physfs library itself from somewhere else too (easiest is to build it yourself, since it doesn't provide prebuilt packages for a while now).
And this is the point where im clueless again.
I downloaded CMake but i have no idea how to build these libraries.
Is there any tutorial how to build physicsfs?
-
Its ok i got it working.. thanks! :)
Althoug id love to know how to create the lib files..
-
How did you get it to work without building it?
-
By including all files to my project... which is ugly and noobish.
Id really like to make libs and include them the right way.
-
Just open CMake GUI, drag CMakeLists.txt into it and then pick your compiler and generate files for it (for VS it'll be a sln with few projects).
-
Thank you.
So Ive created physfs.lib and included it to my project.
And now:
PHYSFS_AddToSearchPath ("Game.zip", 1);
is not defined. :(
-
Once you have the lib and headers the process to use them is the same as with SFML.
-
I know.. but for some reason it doesnt work. Let me write it down:
#include <PhysicsFS/physfs.h>
this is how i include it to my project.
PhysicsFS/lib/
the place of the lib files
PhysicsFS/include/PhysicsFS/
place of my headers
And the vs config is EXACTLY the same as the sfml one.
-
The lib should also be added to AdditionalDependencies in linker input settings.
-
Yes i did, however its not working.
I wonder.. is it really only one single lib? i have a normal one and a static one.
-
Yes, it's a single library. It just can be built as dynamic or static but you need one one of them.
-
C:\Users\*\Desktop\SFML32 - Space Wars\PhysicsFS\include
C:\Users\*\Desktop\SFML32 - Space Wars\PhysicsFS\lib
physfs.lib
-
What is the actual error you are even getting?
-
identifier ""PHYSFS_AddToSearchPath"" is undefined
btw, for example the following works without problems:
PHYSFS_init (0);
-
It's add, not Add. Where did you take the uppercase name from?
From this maybe? https://icculus.org/physfs/physfstut.txt
-
It's add, not Add. Where did you take the uppercase name from?
IT WORKS! HA! Thank you so much ;D
I got it from the tutorial of physicsfs website.
Edit: yes
-
I've sent Ryan Gordon an email about that typo too since it has such time wasting potential. The tutorial code on the SFML wiki is correct though.
-
So one more question. Since i dont understand the tutorial completely, i tried to make it on my own.
PHYSFS_init (0);
PHYSFS_addToSearchPath ("Game.zip", 1);
PHYSFS_file* myfile = PHYSFS_openRead ("Game/Sprites/Title.tga");
sf::Texture tex;
tex.loadFromStream(??);
PHYSFS_close(myfile);
PHYSFS_deinit ();
how do i load myfile to loadfromstream? :(
-
You need a https://www.sfml-dev.org/documentation/2.4.2/classsf_1_1InputStream.php
Like the one from the wiki: https://github.com/SFML/SFML/wiki/Source:-PhysicsFS-Input-Stream
Or you can load entire file into memory and then loadFromMemory.
-
Ok thanks. Ill try my best (looks difficult).
In fact, this is the only thing i dont understand:
tex.loadFromStream(wonderfullStream);
What exactly is returned there? An entire class + sub class?
-
A stream that was created few lines before is passed by reference. It's a normal C++ thing with virtual methods, etc. All the load and open functions in SFML also return a bool to say if it worked or not.
-
Well, thank you very much. Its still a bit complicated to me and i guess i will make this at very last of my game.
I guess my c++ is not good enough yet to understand this :(