mouse and keyboard control using GLUT.


I drew a scene and then tried to move around in it in real time, so I put a “switch” and then a bunch of “cases” for keys and let the glutKeyboradFunc do the work, using gluLookAt, changing the values of variables in it. It works pretty bad. First of all, glut works only with ASCII keys, which exclude arrows. secondly, you have to put gluLookAt into IdleFunc for constant update. Is there a better way to move around in real time, or do I have to use MFC?

For the extended keyboard keys, use glutSpecialFunc. This should notify you of keypresses for the arrows, function keys, etc.

There’s also glutKeyboardUpFunc and glutSpecialUpFunk that register when keys are released if you wanted to use a boolean array for the keys. I recomend opening the glut file so you can get a good idea of all the relevant commands at your disposal.