Using palettes with 32 bit color mode in SDL2?

I’m porting a game developed previously in SDL1.2 to SDL2. Now, it uses 8 bit pixels with palettes. My target platform doesn’t support anything other than 32 bit colors. I am somewhat clueless now, if there is any easy way to solve this. Is there a way to ‘force’ SDL2 to use palettes while drawing to 32 bit surfaces?

You can use SDL_CreateRGBSurfaceWithFormat to create a surface with format type SDL_PIXELFORMAT_INDEX8. This will create a 8bit surface the you can attach a palette to with SDL_SetPaletteColors(surface->format->palette,…). Then lock the surface, change the pixel values, and unlock. You can then take that surface and turn it into a display native texture using SDL_CreateTextureFromSurface which can be used to display on a 32bit display. Hope that answers your question.

1 Like

Thanks for your reply. I’ll try it out tonight!

[Update: Tried your suggested approach and it worked. Thanks a ton! ]