• Advertisement
Sign in to follow this  

glutKeyboardFunc takes 5 frames to update state

This topic is 1768 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi!
I have the keyboard class that initialize the glutKeyboards functions. When I release a key, the program takes five frames to detect. I have another class that when I push the key 's', it add a vec3(1.0,1.0,1.0) to the variable position. The problem is that in each frame from that I press key 's' until it detects that I released it adds to the variable position the vector vec3(1.0,1.0,1.0). The update() function is called before the Draw () function in the render method

KeyboardDevice.cpp

 

 

void KeyboardDevice::keySpecialUp(int key, int x, int y)
{
keySpecialStates[key] = false;
timeReleased = clock();
keySpecialReleaseStates[key] = true; // Set the state of the current special key recently pressed
}
 
bool KeyboardDevice::IsKeyPress(unsigned char key)
{
return keyStates[key];
}
bool KeyboardDevice::IsKeyUp(unsigned char key)
{
double now = clock()/(double)CLOCKS_PER_SEC;
double last = timeReleased /(double)CLOCKS_PER_SEC;
if(now-last < 1 && keyReleaseStates[key] == true)
{
keyReleaseStates[key] = false;
return true;
}
return false;
}

Actor.cpp:

void Cube::Update(void)
{
if(kb->IsKeyPress('s'))
position += glm::vec3(1.0 * getParent()->getEngine()->deltaTime);
}

Any idea to resolve this?

Share this post


Link to post
Share on other sites
Advertisement

GLUT's keyboard input functions are generally too slow for game related purposes.  You'd be best off using your OS specific input APIs which are much faster and reliable.  Assuming you're using Windows, try using GetAsyncKeyState.  I personally recommend using SDL over GLUT when necessary, especially when it comes to input.

 

Shogun.

Share this post


Link to post
Share on other sites

Are you using GLUT or freeGLUT?  If your using GLUT, cease and desist.  GLUT is old and not supported and not free.  Start using freeGLUT immediately.  

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement