Fluent key inputs.

This is a discussion on Fluent key inputs. within the Game Programming forums, part of the General Programming Boards category; I am working on a simple FPS for school in OpenGL, cpp, and I am having an issue with key ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    35

    Fluent key inputs.

    I am working on a simple FPS for school in OpenGL, cpp, and I am having an issue with key inputs being delayed after the first one.

    To simplify; When I hold W to move forward, the character takes one step, pauses(for not even a second), then proceeds to walk forward as he should.

    Id imagine this would be a common issue, but I couldnt find any solutions for it.

    Any help would be great, Thank you

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,404
    I'm no expert in OpenGL (I'm not even a beginner), but it seems to me you might be using some keypress event when in fact what you want to use is keydown.

    Or check for ways in your opengl implementation to test if a key is being held down instead of just pressed and released.
    Last edited by Mario F.; 02-24-2010 at 06:23 PM.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    35
    I found online, GetAsyncKeyState, and used that, but it still gives me the same problem.

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,404
    Well, if you are going outside your OpenGL implementation you might as well move the whole keyboard handling. Build two 256 bit arrays that will indicate the state of your keyboard. WM_KEYDOW and WM_KEYUP events update the corresponding bit of the array. At the end of your current frame, copy the array to the next frame as a Previous State array. Your game main loop keyboard section will check these two arrays instead of whatever you are using now.

    But I'm pretty sure there's something your OpenGL implementation offers that you are not seeing. Someone here will be able to help you a lot better, shortly.
    Last edited by Mario F.; 02-24-2010 at 06:37 PM.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  5. #5
    Registered User
    Join Date
    Feb 2008
    Posts
    35
    mhmm, I dont particularly want to invest my time into that, if thats the only option I will, but there are GLUT keystate commands that could just be intertwined to perform the way I want.

  6. #6
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,404
    ah, Glut.
    Then perhaps check here (after googling for "glut key held"). Anyways, other search results might be more helpful if this isn't.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  7. #7
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Quote Originally Posted by Mario F. View Post
    But I'm pretty sure there's something your OpenGL implementation offers that you are not seeing. Someone here will be able to help you a lot better, shortly.
    The OpenGL standard says nothing about keyboard input, it really has nothing to do with OpenGL.

    How are you using GetAsyncKeyState()? Personally I would build a 256 bit array like Mario suggested. Or pass a queue of "input events" to appropriate modules.
    Last edited by zacs7; 02-24-2010 at 06:59 PM.

  8. #8
    Registered User
    Join Date
    Feb 2008
    Posts
    35
    Quote Originally Posted by zacs7 View Post
    The OpenGL standard says nothing about keyboard input, it really has nothing to do with OpenGL.

    How are you using GetAsyncKeyState()? Personally I would build a 256 bit array like Mario suggested. Or pass a queue of "input events" to appropriate modules.
    Well, I ran this example

    OpenGL @ Lighthouse 3D - GLUT Tutorial

    and its exactly how I want character to move, but now Im having trouble incorporating it

  9. #9
    Registered User
    Join Date
    Feb 2008
    Posts
    35
    Ahhh, got it to work !

    Ty anyways, PM me if anyone is interested to know how, but that tutorial basically tells all

  10. #10
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,404
    Well that's good. But keep in mind that's C code and there are better ways to implement keyboard routines with callbacks that don't end up being one gigantic switch statement in C++ thanks to such things as classes and operator overloading, for instance. Assuming you already studied it -- and considering that your school project is written in C++ -- I'd try to keep the C code to a minimum. Just what the GLUT interface demands of you, while the rest of your logic is all in C++. Otherwise you won't be really doing a C++ project, now will you?

    Anyways, I think the gist of it ended up to be that glutIgnoreKeyRepeat function, am I right?

    Quote Originally Posted by zacs7 View Post
    The OpenGL standard says nothing about keyboard input, it really has nothing to do with OpenGL.
    Hence why I said "implementation". Although I probably should have said "library". Can't really wrap my head around 3D programming. One field I honestly can't get interested enough and have quit trying a long time ago. But thanks for the correction anyway, if it indeed was needed. I was under the impression however you couldn't use OpenGL without some sort of implementation -- that OpenGL is just a specification.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  11. #11
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,616
    Well, if you still want to use pure Windows messages, you can make an array of 256 bools and pass it like this:

    Code:
    bArray['W'] = true;
    
    if (bArray['W'])
      /* ... */
    That's another solution.

  12. #12
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,616
    Sorry, that is the actual implementation of the method i talked about before.

    Code:
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM)
    {
        switch (message)
        {
            /* ... */
              case WM_KEYUP:
                  bArray[LOWORD(wParam)] = false;
              break;
              case WM_KEYDOWN:
                  bArray[LOWORD(wParam)] = false;
              break;
            /* ... */
         }
         
         /* ... */
    }

  13. #13
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,616
    Code:
    case WM_KEYDOWN:
                  bArray[LOWORD(wParam)] = true;
              break;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 12:48 PM
  2. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 09:00 AM
  3. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM
  4. FAQ: Directional Keys - Useing in Console
    By RoD in forum FAQ Board
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21