Glut keyboard response is slow - Any advice?

I would like to use glut to explore opengl, but I’d like the ability to use the keyboard for interactivity. The problem is that with the glut keyboard callback, the keyboard response is slow. You press a key, you get a pause, and then the key repeat is sluggish.

Using straight windows gives much better keyboard responsiveness, but I rather use glut.

Am I missing something in the glut lib that will give me the keyboard responsiveness I’m looking for?

Thanks!

You aren’t doing anything wrong, thats just the way GLUT is. My suggestion is deal with it until you have a better handle on OpenGL and then try to move to Win32. If you know Win32 already the transition won’t be all that difficult.

Nate Miller http://nate.scuzzy.net

If you want key-repeat behaviour without the pause, don’t rely on repeated calls to the glut keydown callback. Instead, have a flag for each key you’re interested in, set it on a keydown (any keydown), clear it on a keyup, and just check it each frame.

glut doesn’t have a keyup (yet) does it?

Use Direct Input,

It’s the fastest thing out their.

Call a
cout << endl;
every frame. That will cause a flush which will get you a faster keyboard response… not the nicest solution. But it actually works. Under Sun/Solaris anyway.
Good luck

Yes phlake, glut does have a keyup. It’s called glutKeyboardUpFunc(), and works just like glutKeyboardFunc().

i was under the impression that that was in glut 3.7, which is still in beta? the green book and this html reference make no mention, anyway. i guess it’s time to look at the .h file… i could really use a keyUp! i ported a java program to c++/opengl/glut which handled keyboard repeating by using keyDown and keyUp events. i couldn’t find a parallel keyUp in glut, and just assumed it wasn’t there.

http://reality.sgi.com/opengl/spec3/spec3.html

Thanks for the suggestions! Not a bad idea to set a flag on keyup and keydown. Yes, glut, or at least the latest version or beta I downloaded, lets you check for key up/down.

At least I know I’m not missing anything.

Other than setting up the opengl modes, what advantage does glut offer?

None really. It’s even been surpassed at that recently. I’m really getting used to SDL to set any screen mode for me without crashing/complaining. Thats something that glut3.7 never used to do for me…

[This message has been edited by Pauly (edited 07-13-2000).]

some sample source from my java app on using keyup/down to manage key repeats.

the goal is that if a key is held down, action shall be taken when the key is first pressed and every 100ms thereafter until the key is released or another is pressed.

/*

key event handler.

*/

public void keyPressed(KeyEvent e)
{
int keycode = e.getKeyCode();
if (gameState == PLAYING) {
switch (keycode)
{
case KeyEvent.VK_UP:
curPiece.rotate(field); // perform action
keyRotate = true; // this is the action flag
keyTimeElapsed = 0; // reset the time elapsed
keyPrevTime = -1; // flag previous time as “unset”
break;
// …
}
}
}

/*

update is called once per frame, prior to paint.

*/

public void update() {

if (gameState == PLAYING) {

    // perform key action, if necessary
    if (keyRotate | | keyRight | | keyLeft) {

        long keyCurTime = (new Date()).getTime();   // time in milliseconds
        if (keyPrevTime == -1)                      // set previous time if it's unset.
            keyPrevTime = keyCurTime;               
        keyTimeElapsed += keyCurTime - keyPrevTime; // add time elapsed for this frame
        keyPrevTime = keyCurTime;                   // set previous time to now

        if (keyTimeElapsed > KEY_DELAY) {           // if it's been more than KEY_DELAY milliseconds
            if (keyRotate)                          // ...and the "rotate" key is pressed...
                curPiece.rotate(field);             // ...take action.

  // ...
  
            keyTimeElapsed -= KEY_DELAY;            // decrement the time elapsed
        }
    }

// …

}

// ....

}

this actually all lines up with a fixed-width font… sorry. looks a bit messy.

[This message has been edited by phlake (edited 07-13-2000).]