add support for building Android version

This commit is contained in:
jettis
2025-09-23 00:27:56 +03:00
parent 62a7f58342
commit 6210fa9c7b
31 changed files with 6614 additions and 59 deletions

View File

@@ -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];