   Keys Events using OpenGL/SDL
  Hi,I am trying to render my first 3D world using OpenGL and SDL. I am having a little and annoying problem with key events using SDL though. I want to update the "sight" of the using of the Z-depth vision. I mean, how deep the user moves through the 3D world.Whenever I press a key (in this case the up and down arrow) the screen does NOT updates until I release the key and press it down again.It is NOT constantly moving through the 3D world, I have to press the arrow key, release it, and press it down again to move! This is the while loop I am using of the game: while( gameRunning ) //While the user doesn't closes the application{glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); //Clear screen and the depth bufferglLoadIdentity();  while (SDL_PollEvent(&event))//check for events  {    //If it was closed with the X    if(event.type == SDL_QUIT)    {   gameRunning = false;    }    if (event.type == SDL_KEYDOWN){   keysHeld[event.key.keysym.sym] = true;    }    if(event.type == SDL_KEYUP){keysHeld[event.key.keysym.sym] = false;    }    if( event.type == SDL_MOUSEBUTTONDOWN )    {   buttonHeld[ event.button.button ] = true;    } if( event.type == SDL_MOUSEBUTTONUP )    {   buttonHeld[ event.button.button] = false;    }    if( event.type == SDL_MOUSEMOTION )    {   buttonX = event.motion.x;   buttonY = event.motion.y;    }  }  if( keysHeld[SDLK_ESCAPE] )    {   gameRunning = false; //Close    }if( keysHeld[SDLK_UP] ){z++;}if( keysHeld[SDLK_DOWN] ){z--;}glTranslatef(0.0f,0.0f, z); //updates "sight"drawQuad(); //Calls functions that draws the quadsglClearColor(0, 0, 0, 0); //Clears screen in black    //Updates screen SDL_GL_SwapBuffers();}Any ideas?Thanks in advance.   
  1. use code tags2. keydown events only occur the first time the key was pressed. You could set a boolean "moveForward" to true, then in your update function have a if(moveForward) { ++z; }" and set moveForward to false again, once you gain an SDL keyup event for that key.3. Don't call glClearColor in your main loop, just once before.   ;  Try switching:drawQuad(); //Calls functions that draws the quadsglClearColor(0, 0, 0, 0); //Clears screen in black//Updates screenSDL_GL_SwapBuffers();to:glClearColor(0, 0, 0, 0); //Clears screen in blackdrawQuad(); //Calls functions that draws the quads//Updates screenSDL_GL_SwapBuffers();;Quote:Original post by Eskapade1. use code tags2. keydown events only occur the first time the key was pressed. You could set a boolean "moveForward" to true, then in your update function have a if(moveForward) { ++z; }" and set moveForward to false again, once you gain an SDL keyup event for that key.3. Don't call glClearColor in your main loop, just once before.No dude, it didn't work.I called glClearColor() before the while loop. And then used the boolean functions, and I keep getting the same problems. :(Btw, how do I use the code tags? I tried with  ;  *Bumps*   ;  Nevermind, I found a simple error. It was a simple solution. I did not initialize the boolean variable "keysHeld" to false :( >___>Thanks to all for your replies, I'll follow your suggestions in my future applications, thank you. :)   ;Quote:Original post by lcruz007Btw, how do I use the code tags? I tried with  Use [sou rce]int foo();[/source], not .Quote:Original post by lcruz007I called glClearColor() before the while loop.Not sure whether you're saying that you fixed it or think it was before the while loop already. Just to make sure: it's called each frame in your while loop. This is not necessary because you set it to the same color every time and OpenGL memorizes that value already, as it uses a state machine to remember settings. I don't think this will cause you any problems in this case, but you should try to avoid such calls, because some of them can be surprisingly expensive.;Quote:Original post by EskapadeQuote:Original post by lcruz007Btw, how do I use the code tags? I tried with  Use [sou rce]int foo();[/source], not .Quote:Original post by lcruz007I called glClearColor() before the while loop.Not sure whether you're saying that you fixed it or think it was before the while loop already. Just to make sure: it's called each frame in your while loop. This is not necessary because you set it to the same color every time and OpenGL memorizes that value already, as it uses a state machine to remember settings. I don't think this will cause you any problems in this case, but you should try to avoid such calls, because some of them can be surprisingly expensive.Ohh Ok, thank you!! :)