I’m trying to make a menu using the SDL2. I have several items consisting of a few indicative words, that I make into surfaces using TTF_RenderText_Blended, then make them into textures through SDL_CreateTextureFromSurface, then display them all in a column, one below another. This works fine, but for the sake of interactivity, I want to make the keyboard shortcut for each item explicit through underlining the corresponding character in each item.
This is my code:
int char_w,char_h; TTF_SizeText(font, "C", &char_w,&char_h);
...
s_item =TTF_RenderText_Blended(font, "> New game", RED);
SDL_Rect r =(SDL_Rect){char_w*3,char_h-5,char_w,3};
SDL_FillRect(s_item, &r, 79);
items[n]->t =SDL_CreateTextureFromSurface(renderer, s_item);
I figured the simpliest way to achieve the effect I wanted was to draw on my surface a slim rectangle under the character I’m interested in, before making it into a texture.
However, this does not work, the text shows on screen but no underline.
I tried a variety of other methods, uselessly more complicated imo, such as creating the texture, setting the render target to that texture and drawing a line, or blitting two surfaces together, to no avail.
Possibly related: https://discourse.libsdl.org/t/problems-with-sdl-ttf-and-surfaces/5431/3f
but I don’t understand the suggested solution.