SDL_SetTextInputRect actually allows text input to rect?

My best try using SDL__SetTextInputRect is in the program listed below. It doesn’t work. For one thing I don’t know what to do about setting the font. The printf statement after the WHILE loop shows that, yes indeed, the text was input while the program was in the loop. But it never shows in the rectangle. Can someone here show me how to get it to put text in the rectangle? Any example will do. TIA Bill S.

Code:

#include <SDL2/SDL.h>
#include <stdio.h>
#include <string.h>

int main( int argc, char* args[] ){

int done = 0;
char text[32];

SDL_Init(SDL_INIT_EVERYTHING);

SDL_DisplayMode vmode;
SDL_GetDisplayMode(0, 0, &vmode);
SDL_Window *win1 = NULL;
win1 = SDL_CreateWindow("", 0, 0, vmode.w, vmode.h, SDL_WINDOW_SHOWN);

SDL_Renderer* ren1 = SDL_CreateRenderer(win1, -1, 0);

SDL_SetRenderDrawColor(ren1, 255, 255, 255, 255);
SDL_RenderClear(ren1); // fill the scene with white

SDL_Rect rect1;
rect1.x = 50;
rect1.y = 50;
rect1.w = 200;
rect1.h = 32;

SDL_RenderDrawRect(ren1, &rect1);
SDL_SetRenderDrawColor(ren1, 255, 0, 0, 255); // the rect color (solid red)
SDL_RenderFillRect(ren1, &rect1);
SDL_RenderPresent(ren1); // copy to screen

SDL_StartTextInput();
SDL_SetTextInputRect(&rect1);
while (!done)
{
SDL_Event event;
if (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
done = 1;
break;
case SDL_TEXTINPUT:
/* Add new text onto the end of our text */
strcat(text, event.text.text);
break;
}
}
SDL_RenderDrawRect(ren1, &rect1);
SDL_RenderPresent(ren1);
}

SDL_StopTextInput();

SDL_Delay(5000);

SDL_DestroyWindow(win1);
SDL_DestroyRenderer(ren1);
SDL_Quit();
printf("\nthe text input is: %s\n\n",text);
return 0;
}

SDL doesn’t have text rendering built in, you’ll need to look at SDL_TTF
for that.

SDL_SetTextInputRect is a function related to SDL’s IME support which
sets the location that an IME candidate list will appear. This is only
relevant to languages that don’t have a 1:1 mapping of key to character.

SDL_TTF: https://www.libsdl.org/projects/SDL_ttf/
SDL IME info: https://wiki.libsdl.org/Tutorials/TextInput

SDL_ttf renders a string to a surface, which you have to convert to a
texture before drawing on the screen.

If you want to do more direct rendering and individual character caching (a
little higher level than SDL_ttf), I put up a library recently that is made
for it:

Jonny DOn Wed, Apr 22, 2015 at 10:14 PM, Alex Baines wrote:

SDL doesn’t have text rendering built in, you’ll need to look at SDL_TTF
for that.

SDL_SetTextInputRect is a function related to SDL’s IME support which
sets the location that an IME candidate list will appear. This is only
relevant to languages that don’t have a 1:1 mapping of key to character.

SDL_TTF: https://www.libsdl.org/projects/SDL_ttf/
SDL IME info: https://wiki.libsdl.org/Tutorials/TextInput


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

2015-04-22 23:14 GMT-03:00, Alex Baines :

SDL_SetTextInputRect is a function related to SDL’s IME support which
sets the location that an IME candidate list will appear. This is only
relevant to languages that don’t have a 1:1 mapping of key to character.

This. I believe that the idea is that you use it to indicate the
area covered by the placeholder text, sadly there isn’t any good
documentation (not just talking about SDL2, the underlying system APIs
are just as unclear about this).