I'm developing a OpenGL application in C++ however I require the user to input an int
and the project to output a double
plus some text. What would be the best way to go about this?

- 347,512
- 102
- 1,199
- 985

- 115
- 11
3 Answers
There's no text input function in OpenGL. You'll have to use an API on top of openGL, for example manage the keyboard entry with the basic GLUT keyboard functions.
For the output, you have to draw it as part of your graphic output as explained in this SO question.
Of course you don't need to reinvent the wheel from scratch and may consider more elaborate API than Glut, as discussed here.
Edit: Just seen today this tweet from Evan Todd with a link to his 160 lines of C++ implementation of in-game console on github. It's based on OpenGL/glfw. His approach could interest you as well.

- 1
- 1

- 68,716
- 7
- 72
- 138
Your job can be split into two part
- Taking
integer
input from user - Show
double + extra text
it on your window
obviously second part is the easy part, use glutStrokeCharacter
to show your double + text
referred here
The first part is little bit tricker, you can make a TextEdit like widget using the glutStrokeCharacter
& glutKeyboardFunc
. The job of the TextEdit will to show the user original int
input. just register the keyboard using glutKeyboardFunc
& on the call back draw the original int inside the TextEdit widget.
glutKeyboardFunc
is referrence here here
suggestion, draw a nice rectangle just behind the TextEdit's to make it seems actual user input :). Happy coding

- 7,484
- 4
- 35
- 44
-
OP never said anything about GLUT. – RamblingMad Jul 25 '15 at 16:03
-
OP never said anything about 'NO GLUT' too. – Ratul Sharker Jul 25 '15 at 16:08
Just found this actually which does exactly what I'm looking for. Thanks for all the responses.
https://justcheckingonall.wordpress.com/2008/08/29/console-window-win32-app/

- 115
- 11
-
how does that relates to openGL ? :P Oh I get it, you needed console along with opengl window :). As far As i know every IDE allow having the console opened and at same time opengl window (and also the final executable get the same, you need to explicitly deploy your code as "console application") – CoffeDeveloper Jul 26 '15 at 10:12