What is the best and simplest way to get input text from user in an OpenGL app?

I have an OpenGL game and and I want to implement a simple way for the user to enter data/text in an input box. What is the easiest method to do this?

• What are you using for input management? – thedaian Sep 1 '11 at 11:02
• Do you want to have OpenGL controls (EditBox, Label, Button)? – Kromster Sep 1 '11 at 11:28
• what is input management? ( im beginner ). for now i just what to get simple Text box or something very simple – user3689 Sep 1 '11 at 11:49
• Input management, as in how are you handling keyboard input from the user. Different libraries handle things differently. – thedaian Sep 1 '11 at 14:37
• tiny file dialogs on sourceforge is a single C C++ cross-platform file offering many modal dialogs including an inputbox. It has no init, no main loop, no linking and no include. – rolobo Sep 17 '17 at 19:12

OpenGL is a rendering system. Rendering has nothing to do with getting text input. If you want text input, then you're going to have to use a library or OS system that provides it.

SDL, Allegro, SFML, and most of the other "multimedia" libraries all have some means of getting input from the user. They're also cross-platform, if you're into that sort of thing. Even the "toy" libraries like GLFW and FreeGLUT have ways of getting basic input.

As for the "text box" part, that's going to be more interesting. Generally, if you're making a game, you don't really interact with the native windowing GUI. So you either have to use a specialized GUI library like CeGUI, or you have to write the text box code yourself. I would personally suggest investigating game-GUI libraries, as writing a GUI yourself is not particularly fun.

• Writing a GUI sounds like a whole lot of fun! Why isn't it fun in your opinion? – Zolomon Oct 2 '11 at 8:18
• The problem with rolling your own GUI system is that it's a pretty complex task and there are almost no tutorials available. – Exilyth Oct 3 '11 at 1:10
• @Zolomon: "Fun" in this context would be "making the game." Things that get in the way of making the game, code you have to write just to get to the point where you can write your game, is not really part of "fun". – Nicol Bolas Oct 3 '11 at 2:06
• @NicolBolas Ah, I see! Guess I'm still stuck in the "Engine Phase", craving to know how to implement the unlimited features, that your ideal game could use, from scratch. – Zolomon Oct 3 '11 at 18:59

I have a 20-year old GLUT program. I need to support command line entry. My solution is epically nasty: I edit the text in the window title bar.

I used the ESC key to toggle a command-line mode. In this mode, the mouse symbol became the text entry bar, and the the current prompt and text was displayed using glutSetWindowTitle(). You can only get the conventional ASCII 7-bit printing characters. I support the printing characters, DEL, and RETURN. I have command history using the arrow keys. There is no cursor symbol, so the only way of moving back is to delete.

The default centres the text. I got left justification of the prompt by appending a lot of spaces.

I don't know, if you want to use just OpenGL or it's also possible to use other libraries. If you can use others, you can try AntTweakBar - gui library for OGL. I have never used it for text input, but there is also string type for variables, so it should work.

You just create bar, add there variable of type string and set callback. When data are changed, you store them to your own variable. Then you add there button. When user presses it, you will just use stored text to whatever you want.

• maybe some method to capture the user keystroke , and then showing him which keys was printed? – user3689 Sep 1 '11 at 13:08
• If you have some app, it's possible you want have mapped some actions to key strokes. So this could be unpropriate. – zacharmarz Sep 1 '11 at 13:52