I want to render some text using a gradient instead of a solid color, but I can't figure out how to. I first load a gradient like this:
SDL_Surface* gradient = IMG_Load("blue-cian.png");
then I render the text I'm using:
SDL_Surface* text = TTF_RenderText_Blended(font, "Text", 30);
then I want to blit the text to the gradient but only keeping the pixels inside the text not the ones surrounding it to create a texture and render it to the screen. I guess I need to use SDL_SetSurfaceAlphaMod and/or SDL_SetSurfaceBlendMode to use only the opaque pixels when blitting the two surfaces. But I don't completely understand how that works and I only get either just a square colored with the gradient:
or a completely transparent square.
This is how it is supposed to look
but I just can't do it, please tell/explain me how to use the rendered text surface as an aplha mask for the gradient.