title: 3D / FPS Camera Issues - SDL2
body: <p>I got a problem with my code, I'm trying to make a First Person 3D Camera.
  I use SDL_GetKeyboardState(NULL) to get the pressed keys.</p>
  
  <p>When I press one of the defined keys nothing happens, why? </p>
  
  <p>Camera (Controll):</p>
  
  <pre><code>void Control(float movevel, float mousevel, bool mi, SDL_Window* window)
  {
  if (mi)  //if the mouse is in the screen
  {
      int MidX = 640 / 2;   //middle of the screen
      int MidY = 480 / 2;
      SDL_ShowCursor(SDL_DISABLE);    //we don't show the cursor
      int tmpx, tmpy;
      SDL_GetMouseState(&amp;tmpx, &amp;tmpy); //get the current position of the cursor
      camYaw += mousevel*(MidX - tmpx);   //get the rotation, for example, if the mouse current position is 315, than 5*0.2, this is for Y
      camPitch += mousevel*(MidY - tmpy); //this is for X
      lockCamera();
      //SDL_WarpMouse(MidX, MidY);       //move back the cursor to the center of the screen
      SDL_WarpMouseInWindow(window, MidX, MidY);
  
      const Uint8* kstate = SDL_GetKeyboardState(NULL);
  
      if (kstate[SDLK_w])
      {
          if (camPitch != 90 &amp;&amp; camPitch != -90)
          {       //if we are facing directly up or down, we don't go forward, it will be commented out, when there will be gravity
              moveCamera(movevel, 0.0);        //move forward
          }
  
          moveCameraUp(movevel, 0.0);      //move up/down
      }
  
      if (kstate[SDLK_s])
      {
          //same, just we use 180 degrees, so we move at the different direction (move back)
          if (camPitch != 90 &amp;&amp; camPitch != -90)
          {
              moveCamera(movevel, 180.0);
          }
  
          moveCameraUp(movevel, 180.0);
      }
  
      if (kstate[SDLK_a])
      {       //move left
          moveCamera(movevel, 90.0);
      }
  
      if (kstate[SDLK_d])
      {  //move right
          moveCamera(movevel, 270);
      }
  }
  
  glRotatef(-camPitch, 1.0, 0.0, 0.0);
  glRotatef(-camYaw, 0.0, 1.0, 0.0);
  }
  </code></pre>
  
  <p>Main (Loop)</p>
  
  <pre><code>while (running)
  {
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      glLoadIdentity();
  
      SDL_Event ev;
      while (SDL_PollEvent(&amp;ev))
      {
          switch (ev.type)
          {
              case SDL_QUIT:
                  running = false;
                  break;
              case SDL_KEYDOWN:
                  int x, y;
  
                  SDL_GetMouseState(&amp;x, &amp;y);
                  Main::handleKeys(ev.key.keysym.scancode, x, y);
                  break;
          }
      }
  
      Main::update(window);
      Main::render(window);
  
      SDL_GL_SwapWindow(window);
  }
  </code></pre>
  
  <p>Main (Update):</p>
  
  <pre><code>void Main::update(SDL_Window* window)
  {
  Control(0.2, 0.2, mousein, window);
  UpdateCamera(0.2); //move the camera to the new location
  }
  </code></pre>