forked from pioneerspacesim/pioneer
/
SDLWrappers.cpp
30 lines (25 loc) · 967 Bytes
/
SDLWrappers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright © 2008-2015 Pioneer Developers. See AUTHORS.txt for details
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
#include "libs.h"
#include "SDLWrappers.h"
#include "FileSystem.h"
#include "utils.h"
SDLSurfacePtr LoadSurfaceFromFile(const std::string &fname, FileSystem::FileSource &source)
{
RefCountedPtr<FileSystem::FileData> filedata = FileSystem::gameDataFiles.ReadFile(fname);
if (!filedata) {
Output("LoadSurfaceFromFile: %s: could not read file\n", fname.c_str());
return SDLSurfacePtr();
}
SDL_RWops *datastream = SDL_RWFromConstMem(filedata->GetData(), filedata->GetSize());
SDL_Surface *surface = IMG_Load_RW(datastream, 1);
if (!surface) {
Output("LoadSurfaceFromFile: %s: %s\n", fname.c_str(), IMG_GetError());
return SDLSurfacePtr();
}
return SDLSurfacePtr::WrapNew(surface);
}
SDLSurfacePtr LoadSurfaceFromFile(const std::string &fname)
{
return LoadSurfaceFromFile(fname, FileSystem::gameDataFiles);
}