5
\$\begingroup\$

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?

\$\endgroup\$
  • \$\begingroup\$ What are you using for input management? \$\endgroup\$ – thedaian Sep 1 '11 at 11:02
  • \$\begingroup\$ Do you want to have OpenGL controls (EditBox, Label, Button)? \$\endgroup\$ – Kromster says support Monica Sep 1 '11 at 11:28
  • \$\begingroup\$ what is input management? ( im beginner ). for now i just what to get simple Text box or something very simple \$\endgroup\$ – user3689 Sep 1 '11 at 11:49
  • \$\begingroup\$ Input management, as in how are you handling keyboard input from the user. Different libraries handle things differently. \$\endgroup\$ – thedaian Sep 1 '11 at 14:37
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – rolobo Sep 17 '17 at 19:12
4
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ Writing a GUI sounds like a whole lot of fun! Why isn't it fun in your opinion? \$\endgroup\$ – Zolomon Oct 2 '11 at 8:18
  • \$\begingroup\$ The problem with rolling your own GUI system is that it's a pretty complex task and there are almost no tutorials available. \$\endgroup\$ – Exilyth Oct 3 '11 at 1:10
  • 1
    \$\begingroup\$ @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". \$\endgroup\$ – Nicol Bolas Oct 3 '11 at 2:06
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ – Zolomon Oct 3 '11 at 18:59
1
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.