diff --git a/library/Console-sdl-impl.cpp b/library/Console-sdl-impl.cpp index f33ffc9aaef..60309f53219 100644 --- a/library/Console-sdl-impl.cpp +++ b/library/Console-sdl-impl.cpp @@ -1391,6 +1391,19 @@ class BMPFontLoader : public FontLoader { return nullptr; } + if (surface->format->format != SDL_PIXELFORMAT_INDEX8) { + SDL_Surface* conv_surface = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_INDEX8, 0); + if (!conv_surface) { + std::cerr << "Error converting surface format: " << SDL_GetError() << std::endl; + SDL_FreeSurface(surface); + return nullptr; + } + + // Free the original surface and use the converted one + SDL_FreeSurface(surface); + surface = conv_surface; + } + // FIXME: hardcoded magenta Uint32 bg_color = sdl_console::SDL_MapRGB(surface->format, 255, 0, 255); sdl_console::SDL_SetColorKey(surface, SDL_TRUE, bg_color);