How to accept input from user command for Opengl C++ program

iam very new to this GLUT. I have some previous knoledge about c++. my problem is that i tried to accept some input through cin command but i failed. can anybody tell how to accept user input for a c++ glut program.
my intension is need to draw a line by accepting point from user at runtime.

hey if it’s a graphics program, why not be visual about it?

allow the user to define the points using a mouse click. A line is defined by two user clicks somewhere on the screen. After the second click render a line from the mouse position at the first mouse click and the second mouse click.

I don’t have much experience with glut so I can’t help with implementation specific stuff…

Hey Graphicsguy,

With glut, you can register an idle function that gets called basically when there’s nothing else to do. You can just write some function that takes no parameters and register it with glutIdleFunc(yourFunction).

Then in that function that you write, you can have it accept user input from the command line. Once you get some data from the user, you’ll probably want to store it in some data structure and then make a call to glutPostRedisplay() to tell glut that you have new stuff that you want to draw.

Hope that helps!


hi both
Thanx for your reply i tried it and now i can able to do it. But about first reply i already told iam just beginer so may be after few days i will implement your suggestion.
again thank you both.

The OpenGL redbook explain that, isn’t it ?

Sounds like you tried to read from the console, that might work if you type into the console where you launched your glut application from (unless you’re on windows and you don’t have a console because of a winmain instead of main entry point).

When getting input using standard libs it helps to know where your input is supposed to come from, especially in a windowed graphical environment where traditional i/o on the command line is explicitly replaced by window based event handling etc.