I'm having a problem for a SDL project, I'd like to show text on the window and allow the user to input text. As much as I know, there is no simple way to achieve that. Do you hava any suggestion? Note: I use C programming langage. I know there is a library called SDL_ttf which doesn't seems to make the job I want.
2 Answers
I have to be honest, as I was reading your question, SDL_ttf immediately sprang to mind. It's not too hard to use and there are plenty of docs available.
What it sounds like you are looking for, is a library that provides a simple console interface, where your main programming interaction is to write(...)
and read(...)
text and it handles display, scrolling and so on.
This project has a lot of code showing how to implement a simple 'console' in SDL, and it does use SDL_ttf to do so.
I'm not convinced you are going to avoid it, unless you grab someone's library that hides it away from you like this one but you are going to have less control over the display and interactivity this provides.

- 6,230
- 12
- 66
- 88

- 1,366
- 7
- 5
-
Thank you for answering, Well, I'm making a simple physics engine that displays physical behaviours, and in my mind, there are two kinds of text for the project. Text displayed. Example: The speed of the sphere, the coordinates of collisions. Text inputted. Example: What is the width of the form. So, some inputted text could be showed on the screen, and some other would just be a "scanf" taking instructions and doing the job, choosing a menu. it's hard because some text using SDL_ttf makes sense, and it would be even more logical to write text directly from SDL... – GoodGuy Jun 10 '11 at 12:12
-
Have a look at http://lazyfoo.net/SDL_tutorials/lesson23/index.php, it deals with reading text input from the user. – Orka Jun 10 '11 at 14:37
I must go with benosteen, SDL_ttf is a really good option. For my part, I used this tutorial to make it work in my project. It's really simple and straightforward.
EDIT: I had some troubles with the Blending functionality of SDL_ttf, but I managed to make it work after QuasarDonkey found the problem in this question.
Have a look for a straight forward example on how to use it and create text surface.

- 1
- 1

- 6,230
- 12
- 66
- 88