PDA

View Full Version : glutSpecialFunc smoother



DirkWillem
03-31-2012, 12:32 PM
Hello

I'm not very advanced on OpenGL and GLUT programming, but i've managed to create a moving square. I'm using a glutSpecialFunc for the key-input, but I find this a bit shocky. It first takes one input, waits a while, and then starts moving very blocky. I'm now using this for my input-code:


void handleKeyInput(int key, int x, int y)
{
if ( key == GLUT_KEY_LEFT )
{
obj_player.x -= 1;
glutPostRedisplay();
}
if ( key == GLUT_KEY_RIGHT )
{
obj_player.x += 1;
glutPostRedisplay();
}
if ( key == GLUT_KEY_UP )
{
obj_player.y += 1;
glutPostRedisplay();
}
if ( key == GLUT_KEY_DOWN )
{
obj_player.y -= 1;
glutPostRedisplay();
}
}

I am calling the specialfunc in a timer, wich updates about 60 times per second, but it doesn't really matter wether I put it there, or just in my main method. So now I'm asking, can this be made smoother, or maybe a completely other way, to get the same effect, but make the movement smooth?

DirkWillem