add support for building Android version
This commit is contained in:
20
SDLHelpers.h
20
SDLHelpers.h
@@ -12,7 +12,11 @@
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
static const char *font_paths[] = {"C:/windows/fonts/", "/usr/share/fonts/TTF/", "./"};
|
||||
#ifdef SDL_PLATFORM_ANDROID
|
||||
#include <SDL3/SDL_iostream.h>
|
||||
#endif
|
||||
|
||||
static const char *font_paths[] = {"C:/windows/fonts/", "/usr/share/fonts/TTF/", "./", "./assets/"};
|
||||
static const short font_path_count = 3;
|
||||
|
||||
static SDL_Rect getRect(Sint16 x, Sint16 y, Uint16 w, Uint16 h) {
|
||||
@@ -34,6 +38,20 @@ static SDL_Color getColor(Uint8 r, Uint8 g, Uint8 b) {
|
||||
|
||||
static TTF_Font *openFont(std::vector<std::string> fonts, int size) {
|
||||
TTF_Font *font = NULL;
|
||||
#ifdef SDL_PLATFORM_ANDROID
|
||||
SDL_IOStream* rw = SDL_IOFromFile("FreeSans.ttf", "rb");
|
||||
if (!rw) {
|
||||
SDL_Log("SDL_IOFromFile failed: %s", SDL_GetError());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
font = TTF_OpenFontIO(rw, 1, size); // 1 = auto-free the IOStream
|
||||
if (!font) {
|
||||
SDL_Log("TTF_OpenFontRW failed: %s", SDL_GetError());
|
||||
return nullptr;
|
||||
}
|
||||
return font;
|
||||
#endif
|
||||
for (int x = 0; x < fonts.size(); x++) {
|
||||
#ifdef SDL_PLATFORM_WINDOWS
|
||||
TCHAR windir[MAX_PATH];
|
||||
|
||||
Reference in New Issue
Block a user