From 2661f62e645a7d25bdb05c56423a83673c1d71ee Mon Sep 17 00:00:00 2001 From: sokripon Date: Mon, 29 Dec 2025 05:26:46 +0100 Subject: [PATCH] Fix texture loading for indexed images by converting to RGBA format --- texture.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/texture.cpp b/texture.cpp index 488d965..569680d 100644 --- a/texture.cpp +++ b/texture.cpp @@ -259,6 +259,16 @@ void TextureResource::load(bool reload) { if(surface==0) throw TextureException(filename); + // Convert indexed images to RGBA for OpenGL compatibility + if(surface->format->BytesPerPixel == 1) { + SDL_Surface* converted = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGBA32, 0); + SDL_FreeSurface(surface); + surface = converted; + if(surface == 0) { + throw TextureException(filename); + } + } + w = surface->w; h = surface->h;