PDA

View Full Version : Improving keyboard response



Spoonofdarkness
11-30-2010, 11:03 AM
I'm fairly new to the OpenGL scene, so my problem may be worded improperly with incorrect terms. If so, I apologise in advance.

I am doing my coding solely on a Ubuntu system, so to make the code more portable, I am relying on GLUT to do the heavy lifting with windows and user input. That said, let me describe my problem:

I am attempting to develop a 2D board game where the keyboards arrow keys can manipulate a "player" piece on a grid of unoccupied squares. To start, I implemented the board system with integers where the players piece would only be in a single given square at any time. The glutSpecialFunc() performs this task perfectly, but as the game progressed, I wanted to make the players piece more free-moving on the board environment. To do this, I altered the player piece coordinate system to be floating-point, instead of integer-based, and the glutSpecialFunc() instead incremented it's coordinates by fractions of numbers.

Ok, all this works so far, but the behaviour of the keyboard functions is a little, for lack of a better word, clunky. When i want to move a small distance, I hit an arrow key. When I want to move a large distance I hold the arrow key, but my problem lies in the response here. My player piece moves a single unit, hesitates for ~1-2 beats then shoots off at a more constant/steady speed across the board.

I know this behaviour is standard for keyboards in the application of, say, a word processor, but I was wondering if there is any way to alter the default reaction of the keyboard?

Any help would be greatly appreciated, and although I would like to resolve this issue within GLUT, I also understand this may be beyond the scope that GLUT was intended.

Thank you all in advance,
Spoon

ZbuffeR
11-30-2010, 12:06 PM
Use GLFW. Way better than glut for a game. http://www.glfw.org/
apt-get install libglfw-dev libglfw2

Anyway, with GLUT you have to do this :
glutSetIgnoreKeyRepeat(true);
And watch for both key down and key up (with glut*UpFunc) events.

Spoonofdarkness
11-30-2010, 12:35 PM
Thank you very much, will begin incorporating GLFW asap.