I’m quite surprised that Google didn’t find a solution. I’m searching for a solution that allows SDL_RWops to be used with std::istream. SDL_RWops is the alternative mechanism for reading/writing data in SDL.
Any links to sites that tackle the problem?
An obvious solution would be to pre-read enough data to memory and then use SDL_RWFromMem. However, that has the downside that I’d need to know the filesize beforehand.
Seems like the problem could somehow be solved by “overriding” SDL_RWops functions…
I feel bad answering my own question, but it preocupied me for some time, and this is the solution I came up with:
Works under the assumptions that istream’s are never freed by SDL (and that they live through the operation). Also only istream support is in, a separate function would be done for ostream — I know I could pass iostream, but that would not allow passing an istream to the conversion function :/.
Any tips on errors or upgrades welcome.