I need to create a texture from a surface with indexed color palette and alter the colors. However, after I set new colors, the rendered texture gets blank.
int main(int argc, char** argv)
{
init();
gSurface = TTF_RenderText_Solid(gFont, "text", fg1);
// text is rendered properly, without following line
SDL_SetPaletteColors(gSurface->format->palette, &fg2, 1, 1);
gTexture = SDL_CreateTextureFromSurface(gRenderer, gSurface);
SDL_SetRenderDrawColor(gRenderer, 255, 255, 255, 255);
SDL_RenderClear(gRenderer);
SDL_RenderCopy(gRenderer, gTexture, NULL, NULL);
SDL_RenderPresent(gRenderer);
SDL_Delay(1000);
quit();
}
I tested this code with software rendering using window surface instead of renderer and pallete changing worked.
Could someone explain me why does it happed and how to fix it?
fg1
andfg2
? \$\endgroup\$